Skip to content

Commit

Permalink
Merge pull request #51 from monzo/add-public-slice-of-generic-error-c…
Browse files Browse the repository at this point in the history
…odes

Add a public slice of generic error codes
  • Loading branch information
Will Sewell authored Nov 24, 2023
2 parents 4a94093 + 99fb5bd commit c625f92
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

// Generic error codes. Each of these has their own constructor for convenience.
// You can use any string as a code, just use the `New` method.
// Warning: any new generic error code must be added to GenericErrorCodes.
const (
ErrBadRequest = "bad_request"
ErrBadResponse = "bad_response"
Expand All @@ -42,6 +43,20 @@ const (
ErrRateLimited = "rate_limited"
)

// GenericErrorCodes is a list of all well known generic error codes.
var GenericErrorCodes = []string{
ErrBadRequest,
ErrBadResponse,
ErrForbidden,
ErrInternalService,
ErrNotFound,
ErrPreconditionFailed,
ErrTimeout,
ErrUnauthorized,
ErrUnknown,
ErrRateLimited,
}

var retryableCodes = []string{
ErrInternalService,
ErrTimeout,
Expand Down Expand Up @@ -188,9 +203,9 @@ func (p *Error) SetIsRetryable(value bool) {
}
}

// SetIsUnexpected can be used to explicitly mark an error as unexpected or not. In practice the vast majority of
// SetIsUnexpected can be used to explicitly mark an error as unexpected or not. In practice the vast majority of
// code should not need to use this. An example use case might be when returning a validation error that must
// mean there is a coding mistake somewhere (e.g. default statement in a switch that is never expected to be
// mean there is a coding mistake somewhere (e.g. default statement in a switch that is never expected to be
// taken). By marking the error as unexpected there is a greater chance that an alert will be sent.
func (p *Error) SetIsUnexpected(value bool) {
if value {
Expand Down

0 comments on commit c625f92

Please sign in to comment.