Skip to content

v0.30.1

Choose a tag to compare

@sunfuze sunfuze released this 02 Nov 06:40
· 14 commits to main since this release
5a2f83e

Retries rate-limited HTTP calls, and decodes error codes that are strings.

Added

  • http.CodeGatewayRateLimited (459101): the code that the unified gateway returns when it rejects a request because of a rate limit.
  • http.ApiError.RetryAfter: how long the server asked the client to wait, read from the Retry-After response header. It is 0 when the response has no such header.

Changed

  • http.Client.Call retries rate-limited requests (#137). A request is rate-limited when the response has HTTP status 429 or code 459101. Call retries such a request up to 5 times. The first wait is 100ms, and each next wait is double the one before it.
    • If the response has a Retry-After header, Call waits for that time instead. The header can be a number of seconds, an HTTP date, or a Go duration such as 1.5s.
    • If the Retry-After time is more than 10s, Call returns the error and does not retry.
    • Call retries every HTTP method, including POST. This is safe because the gateway rejects a rate-limited request before it sends the request on to a service.
    • CallSSE does not retry.
  • A non-200 response with a JSON body that cannot be decoded now returns an *http.ApiError. The error keeps the HTTP status and the trace ID, and its message is the raw body. Before this change, Call returned a JSON decode error.

Fixed

  • An error code that is a string no longer causes a decode failure (#137). An example is {"code":"459101","message":"request too many"}. A code that is a number or a numeric string becomes an int. Any other value becomes 500.

Full changelog: v0.30.0...v0.30.1