Documentation
¶
Overview ¶
Package errors defines the error types returned by the Kodik API client.
StatusError ¶
StatusError is returned whenever the API responds with an HTTP status code other than 200. It carries the exact code, making it easy to handle specific cases such as rate-limiting (429) or authentication errors (401):
resp, err := api.Search(params)
if err != nil {
var statusErr *apierrors.StatusError
if errors.As(err, &statusErr) {
switch statusErr.Code {
case http.StatusUnauthorized:
log.Fatal("invalid API token")
case http.StatusTooManyRequests:
log.Fatal("rate limit exceeded")
default:
log.Fatalf("API error: HTTP %d", statusErr.Code)
}
}
log.Fatal(err)
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrUnsupportedMethod = errors.New("kodik: unsupported HTTP method")
ErrUnsupportedMethod is returned when an HTTP method other than GET or POST is used.
Functions ¶
This section is empty.
Types ¶
type StatusError ¶
type StatusError struct {
Code int
}
StatusError is returned when the API responds with a non-200 HTTP status code.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
Click to show internal directories.
Click to hide internal directories.