rerrors

package
v0.0.0-...-02249b2 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Status

func Status(err error) int

Status checks the runtime type of the error and returns an http status code if the error is model.Error

Types

type Error

type Error struct {
	Type    Type   `json:"type"`
	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 NewBadRequest

func NewBadRequest(reason string) *Error

NewBadRequest to create 400 errors

func NewConflict

func NewConflict(resource, operation, value string) *Error

NewConflict to create 409 erros

func NewForbidden

func NewForbidden(reason string) *Error

NewForbidden to create 403 errors

func NewInternal

func NewInternal() *Error

NewInternal for 500 errors

func NewNotFound

func NewNotFound(name string, value string) *Error

NewNotFound to create an error for 404

func (*Error) Error

func (e *Error) Error() string

Error satisfies standard error interface we can return errors from this package as a regular old go _error_

func (*Error) Status

func (e *Error) Status() int

Status is a mapping errors to status codes Of course, this is somewhat redundant since our errors already map http status codes

type Type

type Type string

Type holds a type string and integer code for the error

const (
	BadRequest Type = "BADREQUEST" // Validation errors
	Internal   Type = "INTERNAL"   // Server (500) and fallback errors
	NotFound   Type = "NOTFOUND"   // For not finding resource
	Forbidden  Type = "FORBIDDEN"  // The client has no access rights to the content so the server is refusing to respond
	Conflict   Type = "CONFLICT"   // Already exists - 409
)

Set of valid errorTypes

Jump to

Keyboard shortcuts

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