Documentation
¶
Index ¶
Constants ¶
View Source
const RequestIDHeader = "X-Request-ID"
RequestIDHeader the header to send the unique request id
Variables ¶
This section is empty.
Functions ¶
func RetrieveSample ¶
func RetrieveSample(r io.ReadCloser) []byte
RetrieveSample retrieves a sample from a reader
Types ¶
type Code ¶
type Code string
const ( CodeUnknownError Code = "unknown_error" CodeInvalidRequest Code = "invalid_request" CodeForbidden Code = "forbidden" CodeNotFound Code = "not_found" CodeInvalidOperation Code = "invalid_operation" CodeConflict Code = "resource_conflict" CodeInvalidContentType Code = "invalid_content_type" CodeValidationError Code = "validation_error" CodeRateLimitExceeded Code = "rate_limit_exceeded" CodeServerError Code = "server_error" CodeEncodingError Code = "encoding_error" CodeRequestError Code = "request_error" CodeHTTPClientError Code = "http_client_error" )
type Error ¶
type Error struct {
// Code the helpers code defined
Code Code `json:"code"`
// StatusCode the HTTP status code (if applicable) from the API response
StatusCode int `json:"status_code"`
// Method is the HTTP method
Method string `json:"method"`
// Resource the requested resource path
Resource string `json:"resource"`
// RequestID the uuid of the request.
RequestID string `json:"request_id"`
// Request a sample of the request body.
// this will be nil if there was either no body on the request
// or the error is not associated with performing the API request.
Request []byte `json:"request,omitempty"`
// Response a sample of the response body.
Response []byte `json:"response"`
// Source this is the underlined error if applicable.
Source string `json:"source,omitempty"`
}
Error a formatted API helpers
func FromRequest ¶
FromRequest generates an error from a http.Request. useful when an error occurs before the Response is generated.
func FromRequestAndSource ¶
FromRequestAndSource generates a wrapped error from a HTTP request, overriding the code and source error.
func FromResponse ¶
FromResponse generates an Error from a request and response. The response body is supplied separately as the stream retrieved in the response is a one-time read, providing it separately ensures we account for this and always return a usable reader.
func FromSource ¶
FromSource generates an wrapped error from a source error.
Click to show internal directories.
Click to hide internal directories.