Search code examples
getstream-io

How to check response headers when using go package


When I hit a rate limit I get an error implementation that tells me to check the response headers for more details.

When I inspect the package, I see errors are defined as such:

type APIError struct {
    Code            int                      `json:"code,omitempty"`
    Detail          string                   `json:"detail,omitempty"`
    Duration        Duration                 `json:"duration,omitempty"`
    Exception       string                   `json:"exception,omitempty"`
    ExceptionFields map[string][]interface{} `json:"exception_fields,omitempty"`
    StatusCode      int                      `json:"status_code,omitempty"`
}

How am I able to access the request header information from this? Will it be returned within ExceptionFields? I'd like to add an exponential backoff system as suggested but would like to be able to apply a smarter backoff using the response headers.


Solution

  • I've just seen that the latest version of stream-go2 has a Rate field I can use to check this.

    type APIError struct {
        Code            int                      `json:"code,omitempty"`
        Detail          string                   `json:"detail,omitempty"`
        Duration        Duration                 `json:"duration,omitempty"`
        Exception       string                   `json:"exception,omitempty"`
        ExceptionFields map[string][]interface{} `json:"exception_fields,omitempty"`
        StatusCode      int                      `json:"status_code,omitempty"`
        Rate            *Rate                    `json:"-"`
    }
    

    I'll upgrade our dependency