rout

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: Apache-2.0 Imports: 6 Imported by: 4

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 (
	ErrBadRequest                = errors.New("bad request")
	ErrInvalidCredentials        = errors.New("the provided credentials are missing or invalid")
	ErrExpiredCredentials        = errors.New("the provided 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")
	ErrPermissionDenied          = errors.New("you are not authorized to perform this action")
	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@theopenlane.io for assistance.")
	ErrSendPasswordResetFailed   = response("Unable to send password reset email. Please contact support@theopenlane.io for assistance.")
	ErrPasswordResetFailed       = response("Unable to reset your password. Please contact support@theopenlane.io 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 IsForeignKeyConstraintError

func IsForeignKeyConstraintError(err error) bool

IsForeignKeyConstraintError reports if the error resulted from a database foreign-key constraint violation. e.g. parent row does not exist.

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 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 ErrorCode

type ErrorCode string

ErrorCode is returned along side error messages for better error handling

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 GraphQLRequest

type GraphQLRequest struct {
	Query string `json:"query"`
}

type GraphQLResponse

type GraphQLResponse struct {
	Data   any     `json:"data"`
	Errors []error `json:"errors,omitempty"`
}

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

func ErrorResponseWithCode(err interface{}, code ErrorCode) Reply

ErrorResponseWithCode constructs a new response for an error the contains an error code

type Response

type Response struct {
	Success bool    `json:"success"`
	Message string  `json:"message"`
	Data    any     `json:"data,omitempty"`
	Errors  []error `json:"errors,omitempty"`
}

func (Response) MarshalJSON

func (res Response) MarshalJSON() ([]byte, error)

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 the API

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 Created

func Created() StatusError

func InternalError

func InternalError() StatusError

func InternalServerError

func InternalServerError() StatusError

InternalServerError returns a JSON 500 response for the API

func InvalidRequest

func InvalidRequest() StatusError

InvalidRequest returns a JSON 400 response for the API

func NotFound

func NotFound() StatusError

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