rout

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package rout is a semi-centralized method of handling and surfacing user facing errors

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCredentials        = errors.New("datum credentials are missing or invalid")
	ErrExpiredCredentials        = errors.New("datum 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@datum.net for assistance.")
	ErrSendPasswordResetFailed   = response("Unable to send password reset email. Please contact support@datum.net for assistance.")
	ErrPasswordResetFailed       = response("Unable to reset your password. Please contact support@datum.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 ConflictingFields(fields ...string) error

func ErrorStatus

func ErrorStatus(err error) int

ErrorStatus returns the HTTP status code from an error or 500 if the error is not a StatusError.

func HTTPErrorResponse

func HTTPErrorResponse(err interface{}) *echo.HTTPError

HTTPErrorResponse constructs a new response for an error or simply returns unsuccessful

func InvalidField

func InvalidField(field string) error

func MissingField

func MissingField(field string) error

func NotAllowed

func NotAllowed(c echo.Context) error

NotAllowed returns a JSON 405 response for the API.

func NotFound

func NotFound(c echo.Context) error

func RestrictedField

func RestrictedField(field string) error

func Unverified

func Unverified(c echo.Context) error

Unverified returns a JSON 403 response indicating that the user has not verified their email address.

Types

type FieldError

type FieldError struct {
	Field string `json:"field"`
	Err   error  `json:"error"`
}

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"`
	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

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 datum

func BadRequest

func BadRequest() StatusError

BadRequest returns a JSON 400 response for the API

func Conflict

func Conflict() StatusError

Conflict returns a JSON 409 response for the API

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL