Documentation
¶
Index ¶
- Constants
- func GRPCStatusCode(code Code) codes.Code
- func HTTPStatusCode(code Code) int
- func IsBadRequest(e error) bool
- func IsConflict(e error) bool
- func IsForbidden(e error) bool
- func IsInternalServerError(e error) bool
- func IsInvalidParam(e error) bool
- func IsNotFound(e error) bool
- func IsUnauthorized(e error) bool
- func NewFromError(err error) error
- func NewFromSQL(err error) error
- func StatusText(errCode Code) string
- type AppError
- func Convert(e error) *AppError
- func NewBadRequest(field string, message string, args ...interface{}) *AppError
- func NewConflict(field string) *AppError
- func NewConflictR(field string, message string, args ...interface{}) *AppError
- func NewError(code Code, field string, message string, args ...interface{}) *AppError
- func NewForbidden() *AppError
- func NewForbiddenR(reason string) *AppError
- func NewInvalidParam(field string, message string, args ...interface{}) *AppError
- func NewNotFound() *AppError
- func NewNotFoundField(field string, reason string) *AppError
- func NewNotFoundR(reason string) *AppError
- func NewServerError(message string, args ...interface{}) *AppError
- func NewUnauthorized() *AppError
- func NewUnauthorizedR(reason string) *AppError
- type Code
- type Error
Constants ¶
const (
// ErrDup contains the errcode of a unique constraint violation
ErrDup = "23505"
)
Variables ¶
This section is empty.
Functions ¶
func GRPCStatusCode ¶
GRPCStatusCode returns the GRPC Code corresponding to the provided app error status code
func HTTPStatusCode ¶
HTTPStatusCode returns the HTTP Code corresponding to the provided app error status code
func IsBadRequest ¶
IsBadRequest checks if an error is caused by a bad request
func IsConflict ¶
IsConflict checks if an error is caused by a conflict
func IsForbidden ¶
IsForbidden checks if an error is caused by a forbidden access
func IsInternalServerError ¶
IsInternalServerError checks if an error is caused by an internal error
func IsInvalidParam ¶
IsInvalidParam checks if an error is caused by an invalid param
func IsUnauthorized ¶
IsUnauthorized checks if an error is caused by an Unauthorized access
func NewFromError ¶
NewFromError returns an api error based on an error the provided error will be returned if it doesn't match any known error
func NewFromSQL ¶
NewFromSQL returns an error based on a pq.Error the provided error will be returned if it's not a pq.Error instance, or if the error cannot be matched to
Types ¶
type AppError ¶
type AppError struct {
// contains filtered or unexported fields
}
AppError represents an error with a status code and an optional field
func NewBadRequest ¶
NewBadRequest returns an error caused by a user. Example: A missing param
func NewConflict ¶
NewConflict returns an error caused by a conflict with the current state of the app. Example: A duplicate slug
func NewConflictR ¶
NewConflictR returns an error caused by a conflict with the current state of the app. A reason is sent back to the user.
func NewForbidden ¶
func NewForbidden() *AppError
NewForbidden returns an error caused by a user trying to access a protected resource.
func NewForbiddenR ¶
NewForbiddenR returns an error caused by a user trying to access a protected resource. A reason is sent back to the user.
func NewInvalidParam ¶
NewInvalidParam is an alias for NewBadRequest
func NewNotFound ¶
func NewNotFound() *AppError
NewNotFound returns an error caused by a user trying to access a resource that does not exists
func NewNotFoundField ¶
NewNotFoundField returns an error caused by a user trying to access a resource that does not exists. A reason is sent back to the user.
func NewNotFoundR ¶
NewNotFoundR returns an error caused by a user trying to access a resource that does not exists. A reason is sent back to the user.
func NewServerError ¶
NewServerError returns an Internal Error.
func NewUnauthorized ¶
func NewUnauthorized() *AppError
NewUnauthorized returns an error caused by a anonymous user trying to access a protected resource
func NewUnauthorizedR ¶
NewUnauthorizedR returns an error caused by a anonymous user trying to access a protected resource. A reason is sent back to the user.
func (*AppError) StatusCode ¶
StatusCode returns the HTTP code associated to the error
type Code ¶
type Code uint
Code represent an Error code
const ( // NoError is a "zero value" representation of an error. // Useful in tests NoError Code = 0 // InvalidArgument is returned when a user provided data is invalid InvalidArgument Code = 100 // NotFound indicates a requested entity was not found NotFound Code = 101 // AlreadyExists indicates an attempt to create an entity failed because // it already exists AlreadyExists Code = 102 // Unauthenticated indicates the request does not have a valid // authentication credentials Unauthenticated Code = 103 // PermissionDenied indicates the requester does not have the right // permissions to execute the request PermissionDenied Code = 104 // Internal indicates something the service is internally broken Internal Code = 1000 )
type Error ¶
type Error interface { error // StatusCode return the HTTP code of the error StatusCode() Code // Field returns the http/sql/etc. field associated to the error Field() string // Origin returns the original error if there's one Origin() error }
Error represents an error with a code attached.