Documentation ¶
Index ¶
- Constants
- type Error
- func BadRequest(format string, a ...interface{}) *Error
- func Forbidden(format string, a ...interface{}) *Error
- func InternalService(format string, a ...interface{}) *Error
- func NotFound(format string, a ...interface{}) *Error
- func PreconditionFailed(format string, a ...interface{}) *Error
- func Timeout(format string, a ...interface{}) *Error
- func Unauthorized(format string, a ...interface{}) *Error
- func Wrap(err error, metadata map[string]string) *Error
Constants ¶
const ( ErrBadRequest = "bad_request" ErrForbidden = "forbidden" ErrInternalService = "internal_service" ErrNotFound = "not_found" ErrPreconditionFailed = "precondition_failed" ErrTimeout = "timeout" )
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.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct { Code string `json:"code"` Message string `json:"message"` Metadata map[string]string `json:"metadata"` }
Error is a custom error type that implements Go's error interface
func BadRequest ¶
BadRequest creates a new error to represent an error caused by the client sending an invalid request. This is non-retryable unless the request is modified.
func Forbidden ¶
Forbidden creates a new error representing a resource that cannot be accessed with the current authorisation credentials. The user may need authorising, or if authorised, may not be permitted to perform this action.
func InternalService ¶
InternalService creates a new error to represent an internal service error
func PreconditionFailed ¶
PreconditionFailed creates a new error indicating that one or more conditions given in the request evaluated to false when tested on the server
func Unauthorized ¶
Unauthorized creates a new error indicating that authentication is required, but has either failed or not been provided.
func (*Error) GetMetadata ¶
func (*Error) HTTPStatus ¶
HTTPStatus returns an appropriate HTTP status code to use when returning the error in a response