Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

feat: pass Retry-After to end user #56

Merged
merged 4 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ func (e *exchangeBsWrapper) Close() error {
}

// gatewayError translates underlying blockstore error into one that gateway code will return as HTTP 502 or 504
// it also makes sure Retry-After hint from remote blockstore will be passed to HTTP client, if present.
func gatewayError(err error) error {
if errors.Is(err, gateway.ErrGatewayTimeout) || errors.Is(err, gateway.ErrBadGateway) {
if errors.Is(err, &gateway.ErrorResponse{}) ||
errors.Is(err, &gateway.ErrorRetryAfter{}) {
Comment on lines +73 to +74
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ this removes the need for listing every error code

// already correct error
return err
}
Expand All @@ -82,6 +84,16 @@ func gatewayError(err error) error {
return fmt.Errorf("%w: %s", gateway.ErrGatewayTimeout, err.Error())
}

// Saturn errors with RetryAfter hint need to be converted to Gateway ones
var saturnTooManyRequests *caboose.ErrSaturnTooManyRequests
if errors.As(err, &saturnTooManyRequests) {
return gateway.NewErrorRetryAfter(saturnTooManyRequests, saturnTooManyRequests.RetryAfter)
}
var saturnCidCoolDown *caboose.ErrCidCoolDown
if errors.As(err, &saturnCidCoolDown) {
return gateway.NewErrorRetryAfter(saturnCidCoolDown, saturnCidCoolDown.RetryAfter)
}
hacdias marked this conversation as resolved.
Show resolved Hide resolved

// everything else returns 502 Bad Gateway
return fmt.Errorf("%w: %s", gateway.ErrBadGateway, err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/ipfs/go-ipfs-exchange-interface v0.2.0
github.com/ipfs/go-ipld-format v0.4.0
github.com/ipfs/go-ipns v0.3.0
github.com/ipfs/go-libipfs v0.6.1-0.20230224152609-00e024995173
github.com/ipfs/go-libipfs v0.6.1-0.20230306084414-15f2131fe190
github.com/ipfs/go-log/v2 v2.5.1
github.com/ipfs/go-merkledag v0.9.0
github.com/ipfs/go-namesys v0.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ github.com/ipfs/go-ipld-legacy v0.1.1 h1:BvD8PEuqwBHLTKqlGFTHSwrwFOMkVESEvwIYwR2
github.com/ipfs/go-ipld-legacy v0.1.1/go.mod h1:8AyKFCjgRPsQFf15ZQgDB8Din4DML/fOmKZkkFkrIEg=
github.com/ipfs/go-ipns v0.3.0 h1:ai791nTgVo+zTuq2bLvEGmWP1M0A6kGTXUsgv/Yq67A=
github.com/ipfs/go-ipns v0.3.0/go.mod h1:3cLT2rbvgPZGkHJoPO1YMJeh6LtkxopCkKFcio/wE24=
github.com/ipfs/go-libipfs v0.6.1-0.20230224152609-00e024995173 h1:GO24W9RndedkB5jSuPbxPsF4wy0ZpqrXYG+Lf0RrdKY=
github.com/ipfs/go-libipfs v0.6.1-0.20230224152609-00e024995173/go.mod h1:3OoEQs95UkqFEf65SbRDpiMwuzI+C/jTsYQaHfBbJXI=
github.com/ipfs/go-libipfs v0.6.1-0.20230306084414-15f2131fe190 h1:uLCIMrKU1/SlZVDrTNfX3p6y4hv+cSZn51xiKU3glV8=
github.com/ipfs/go-libipfs v0.6.1-0.20230306084414-15f2131fe190/go.mod h1:FmhKgxMOQA572TK5DA3MZ5GL44ZqsMHIrkgK4gLn4A8=
github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM=
github.com/ipfs/go-log v1.0.2/go.mod h1:1MNjMxe0u6xvJZgeqbJ8vdo2TKaGwZ1a0Bpza+sr2Sk=
github.com/ipfs/go-log v1.0.3/go.mod h1:OsLySYkwIbiSUR/yBTdv1qPtcE4FW3WPWk/ewz9Ru+A=
Expand Down