errors

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeInternal = iota + 100
	CodeNotFound
	CodeBadRequest
	CodeUnauthorized
	CodeConflict
)

Variables

View Source
var (
	Internal = Error{
		Message:    "Internal Server Error",
		Code:       CodeInternal,
		HttpStatus: http.StatusInternalServerError,
	}
	NotFound = Error{
		Message:    "Not found",
		HttpStatus: CodeNotFound,
		Code:       http.StatusNotFound,
	}
	BadRequest = Error{
		Message:    "Bad request",
		HttpStatus: CodeBadRequest,
		Code:       http.StatusBadRequest,
	}
	Unauthorized = Error{
		Message:    "Unauthorized",
		HttpStatus: http.StatusUnauthorized,
		Code:       CodeUnauthorized,
	}
	Conflict = Error{
		Message:    "Conflict",
		HttpStatus: http.StatusConflict,
		Code:       CodeConflict,
	}
)

Functions

func GQLErrPresenter

func GQLErrPresenter(ctx context.Context, e error) *gqlerror.Error

Types

type Error

type Error struct {
	Code       int    `json:"code,omitempty"`
	Message    string `json:"message"`
	Detail     error  `json:"-"`
	HttpStatus int    `json:"-"`
}

func (Error) Error

func (e Error) Error() string

func (Error) WithCode

func (e Error) WithCode(code int) *Error

func (Error) WithDetail

func (e Error) WithDetail(err error) *Error

func (Error) WithMessage

func (e Error) WithMessage(msg string) *Error

func (Error) WithStatus

func (e Error) WithStatus(status int) *Error

Jump to

Keyboard shortcuts

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