Skip to content

Commit

Permalink
Merge pull request #263 from coinbase/patrick/408-transient
Browse files Browse the repository at this point in the history
[client] Handle 408 Status Code as Retriable
  • Loading branch information
patrick-ogrady committed Dec 4, 2020
2 parents b319989 + 80804f8 commit f471414
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 21 deletions.
6 changes: 4 additions & 2 deletions client/api_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ func (a *AccountAPIService) AccountBalance(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down Expand Up @@ -205,7 +206,8 @@ func (a *AccountAPIService) AccountCoins(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down
6 changes: 4 additions & 2 deletions client/api_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func (a *BlockAPIService) Block(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down Expand Up @@ -205,7 +206,8 @@ func (a *BlockAPIService) BlockTransaction(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down
3 changes: 2 additions & 1 deletion client/api_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ func (a *CallAPIService) Call(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down
24 changes: 16 additions & 8 deletions client/api_construction.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ func (a *ConstructionAPIService) ConstructionCombine(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down Expand Up @@ -188,7 +189,8 @@ func (a *ConstructionAPIService) ConstructionDerive(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down Expand Up @@ -273,7 +275,8 @@ func (a *ConstructionAPIService) ConstructionHash(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down Expand Up @@ -365,7 +368,8 @@ func (a *ConstructionAPIService) ConstructionMetadata(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down Expand Up @@ -451,7 +455,8 @@ func (a *ConstructionAPIService) ConstructionParse(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down Expand Up @@ -542,7 +547,8 @@ func (a *ConstructionAPIService) ConstructionPayloads(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down Expand Up @@ -631,7 +637,8 @@ func (a *ConstructionAPIService) ConstructionPreprocess(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down Expand Up @@ -719,7 +726,8 @@ func (a *ConstructionAPIService) ConstructionSubmit(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down
3 changes: 2 additions & 1 deletion client/api_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func (a *EventsAPIService) EventsBlocks(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down
6 changes: 4 additions & 2 deletions client/api_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func (a *MempoolAPIService) Mempool(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down Expand Up @@ -191,7 +192,8 @@ func (a *MempoolAPIService) MempoolTransaction(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down
9 changes: 6 additions & 3 deletions client/api_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func (a *NetworkAPIService) NetworkList(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down Expand Up @@ -188,7 +189,8 @@ func (a *NetworkAPIService) NetworkOptions(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down Expand Up @@ -273,7 +275,8 @@ func (a *NetworkAPIService) NetworkStatus(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down
3 changes: 2 additions & 1 deletion client/api_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func (a *SearchAPIService) SearchTransactions(
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down
3 changes: 2 additions & 1 deletion templates/client/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx _context.Context{{#hasParams
return nil, &v, fmt.Errorf("%+v", v)
case _nethttp.StatusBadGateway,
_nethttp.StatusServiceUnavailable,
_nethttp.StatusGatewayTimeout:
_nethttp.StatusGatewayTimeout,
_nethttp.StatusRequestTimeout:
return nil, nil, fmt.Errorf(
"%w: code: %d body: %s",
ErrRetriable,
Expand Down

0 comments on commit f471414

Please sign in to comment.