api_errors

package
v0.0.0-...-841f565 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BadRequest = APIError{
	Message: "bad request",
	Status:  http.StatusBadRequest,
	Code:    "BAD_REQUEST",
}

BadRequest an error indicating a bad request

View Source
var InternalServerError = APIError{
	Message: "an internal server error occurred",
	Status:  http.StatusInternalServerError,
	Code:    "INTERNAL_SERVER_ERROR",
}

InternalServerError a standard API error message

View Source
var NotFoundError = APIError{
	Message: "no resource found",
	Status:  http.StatusNotFound,
	Code:    "NOT_FOUND",
}

NotFoundError an error indicating the resource couldn't be locating using the provided parameters

Functions

func NewErrorHandler

func NewErrorHandler(logger logz.FieldLogger) fiber.ErrorHandler

NewErrorHandler returns a fiber compatible error handler

Types

type APIError

type APIError struct {
	Message string                 `json:"message"`
	Status  int                    `json:"status"`
	Code    string                 `json:"code"`
	Context map[string]interface{} `json:"context"`
}

APIError the base element of an API error

func (APIError) Error

func (e APIError) Error() string

func (APIError) WithContext

func (e APIError) WithContext(context map[string]interface{}) APIError

WithContext creates a copy of the error with added context values

func (APIError) WithErr

func (e APIError) WithErr(err error) APIError

WithErr returns a new instance of the error with added error context values

func (APIError) WithField

func (e APIError) WithField(field string, value interface{}) APIError

WithField appends an arbitrary field and value to the context map

Jump to

Keyboard shortcuts

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