Documentation ¶
Overview ¶
Package rout is a semi-centralized method of handling and surfacing user facing errors
Index ¶
- Variables
- func ConflictingFields(fields ...string) error
- func ErrorStatus(err error) int
- func HTTPErrorResponse(err interface{}) *echo.HTTPError
- func InvalidField(field string) error
- func MissingField(field string) error
- func NotAllowed(c echo.Context) error
- func NotFound(c echo.Context) error
- func RestrictedField(field string) error
- func Unverified(c echo.Context) error
- type ErrorCode
- type FieldError
- type MissingRequiredFieldError
- type Reply
- type StatusError
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidCredentials = errors.New("central-server credentials are missing or invalid") ErrExpiredCredentials = errors.New("central-server credentials have expired") ErrPasswordMismatch = errors.New("passwords do not match") ErrPasswordTooWeak = errors.New("password is too weak: use a combination of upper and lower case letters, numbers, and special characters") ErrMissingID = errors.New("missing required id") ErrMissingField = errors.New("missing required field") ErrInvalidField = errors.New("invalid or unparsable field") ErrRestrictedField = errors.New("field restricted for request") ErrConflictingFields = errors.New("only one field can be set") ErrModelIDMismatch = errors.New("resource id does not match id of endpoint") ErrUserExists = errors.New("user or organization already exists") ErrInvalidUserClaims = errors.New("user claims invalid or unavailable") ErrUnparsable = errors.New("could not parse request") ErrUnknownUserRole = errors.New("unknown user role") ErrTryLoginAgain = response("Unable to login with those details - please try again!") ErrTryRegisterAgain = response("Unable to register with those details - please try again!") ErrTryOrganizationAgain = response("Unable to create or access that organization - please try again!") ErrTryProfileAgain = response("Unable to create or access user profile - please try again!") ErrTryResendAgain = response("Unable to resend email - please try again!") ErrMemberNotFound = response("Team member with the specified ID was not found.") ErrMissingOrganizationName = response("Organization name is required.") ErrMissingOrganizationDomain = response("Organization domain is required.") ErrOrganizationNotFound = response("Organization with the specified ID was not found.") ErrLogBackIn = response("Logged out of your account - please log back in!") ErrVerifyEmail = response("Please verify your email address and try again!") ErrInvalidEmail = response("Please enter a valid email address.") ErrVerificationFailed = response("Email verification failed. Please contact support@central-server.net for assistance.") ErrSendPasswordResetFailed = response("Unable to send password reset email. Please contact support@central-server.net for assistance.") ErrPasswordResetFailed = response("Unable to reset your password. Please contact support@central-server.net for assistance.") ErrRequestNewInvite = response("Invalid invitation link - please request a new one!") ErrSomethingWentWrong = response("Oops - something went wrong!") ErrBadResendRequest = response("Unable to resend email - please update request and try again.") ErrRequestNewReset = response("Unable to reset your password - please request a new password reset.") AllResponses = map[string]struct{}{} )
Functions ¶
func ConflictingFields ¶
func ErrorStatus ¶
ErrorStatus returns the HTTP status code from an error or 500 if the error is not a StatusError.
func HTTPErrorResponse ¶
HTTPErrorResponse constructs a new response for an error or simply returns unsuccessful
func InvalidField ¶
func MissingField ¶
func NotAllowed ¶
NotAllowed returns a JSON 405 response for the API.
func RestrictedField ¶
func Unverified ¶
Unverified returns a JSON 403 response indicating that the user has not verified their email address.
Types ¶
type ErrorCode ¶
type ErrorCode string
ErrorCode is returned along side error messages for better error handling
type FieldError ¶
FieldError provides a general mechanism for specifying errors with specific API object fields such as missing required field or invalid field and giving some feedback about which fields are the problem
func (*FieldError) Error ¶
func (e *FieldError) Error() string
func (*FieldError) Is ¶
func (e *FieldError) Is(target error) bool
func (*FieldError) Unwrap ¶
func (e *FieldError) Unwrap() error
type MissingRequiredFieldError ¶
type MissingRequiredFieldError struct { // RequiredField that is missing RequiredField string `json:"required_field"` }
MissingRequiredFieldError is returned when a required field was not provided in a request
func NewMissingRequiredFieldError ¶
func NewMissingRequiredFieldError(field string) *MissingRequiredFieldError
NewMissingRequiredFieldError returns an error for a missing required field
func (*MissingRequiredFieldError) Error ¶
func (e *MissingRequiredFieldError) Error() string
Error returns the InvalidEmailConfigError in string format
type Reply ¶
type Reply struct { Success bool `json:"success" yaml:"success" description:"Whether or not the request was successful or not"` Error string `json:"error,omitempty" yaml:"error,omitempty" description:"The error message if the request was unsuccessful"` ErrorCode ErrorCode `json:"error_code,omitempty" yaml:"error_code,omitempty" description:"The error code if the request was unsuccessful"` Unverified bool `json:"unverified,omitempty" yaml:"unverified,omitempty"` }
Reply contains standard fields that are used for generic API responses and errors
func ErrorResponse ¶
func ErrorResponse(err interface{}) Reply
ErrorResponse constructs a new response for an error or simply returns unsuccessful
func ErrorResponseWithCode ¶
ErrorResponseWithCode constructs a new response for an error the contains an error code
type StatusError ¶
type StatusError struct { StatusCode int `json:"code" yaml:"code" description:"the response HTTP code also in the response payload for your parsing convenience"` Reply Reply `` /* 149-byte string literal not displayed */ }
StatusError decodes an error response from central-server
func InternalServerError ¶
func InternalServerError() StatusError
InternalServerError returns a JSON 500 response for the API
func Unauthorized ¶
func Unauthorized() StatusError
Unauthorized returns a JSON 401 response for the API
func (*StatusError) Error ¶
func (e *StatusError) Error() string