Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a public slice of generic error codes #51

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading