Documentation ¶
Index ¶
- func Status(err error) int
- type Error
- func NewAuthorization(reason string) *Error
- func NewBadRequest(reason string) *Error
- func NewConflict(name string, value string) *Error
- func NewInternal() *Error
- func NewNotFound(name string, value string) *Error
- func NewPayloadTooLarge(maxBodySize int64, contentLength int64) *Error
- func NewServiceUnavailable() *Error
- func NewUnsupportedMediaType(reason string) *Error
- type Response
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
type Error struct { Type Type `json:"type"` Code int `json:"code"` Message string `json:"message"` }
Error holds a custom error for the application which is helpful in returning a consistent error type/message from API endpoints
func NewAuthorization ¶
NewAuthorization to create a 401
func NewBadRequest ¶
NewBadRequest to create 400 errors (validation, for example)
func NewConflict ¶
NewConflict to create an error for 409
func NewNotFound ¶
NewNotFound to create an error for 404
func NewPayloadTooLarge ¶
NewPayloadTooLarge to create an error for 413
func NewServiceUnavailable ¶
func NewServiceUnavailable() *Error
NewServiceUnavailable to create an error for 503
func NewUnsupportedMediaType ¶
NewUnsupportedMediaType to create an error for 415
type Response ¶
type Response struct { Error *Error `json:"error,omitempty"` Data interface{} `json:"data,omitempty"` }
Response return response for error
type Type ¶
type Type string
Type holds a type string and integer code for the error
const ( Authorization Type = "AUTHORIZATION" // Authentication Failures - BadRequest Type = "BAD_REQUEST" // Validation errors / BadInput Conflict Type = "CONFLICT" // Already exists (eg, create account with existent email) - 409 Internal Type = "INTERNAL" // Server (500) and fallback errors NotFound Type = "NOT_FOUND" // For not finding resource PayloadTooLarge Type = "PAYLOAD_TOO_LARGE" // For uploading tons of JSON, or an image over the limit - 413 UnsupportedMediaType Type = "UNSUPPORTED_MEDIA_TYPE" // for http 415 )
"Set" of valid errorTypes
Click to show internal directories.
Click to hide internal directories.