errorx

package module
v0.0.0-...-8e33440 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: Apache-2.0 Imports: 7 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTokenInvalid is raised when token is invalid
	ErrTokenInvalid = errors.New("invalid token")

	// ErrTokenCheck is raised when check validity token failed
	ErrTokenCheck = errors.New("check validity token failed")

	// ErrTokenNotFound is raise when HTTP header does not contain Authorization
	ErrTokenNotFound = errors.New("authorization not found in http header")

	// ErrUnAuthorized is raised by check token on kratos with a non authorized token
	ErrUnAuthorized = errors.New("401 Unauthorized")

	// ErrMethod is raised when a internal call failed
	ErrMethod = errors.New("resource can't be empty")

	// ErrServiceUnavailable is raised when a remote service fail to response
	ErrServiceUnavailable = errors.New("service unavailable")
)

Functions

func Error2code

func Error2code(err error) int

Error2code return the http code according the Error code field or try to deduce it from the error itself

func ErrorEncoder

func ErrorEncoder(ctx context.Context, err error, w http.ResponseWriter)

ErrorEncoder writes the error into http.ResponseWriter

func New

func New(err error, message string) error

New returns Error with err in Cause and message

func NewErrorHandler

func NewErrorHandler() transport.ErrorHandler

NewErrorHandler returns an instance of transport.ErrorHandler

func NewHTTP

func NewHTTP(err error, code int, message string) error

NewHTTP returns Error with err in Cause, code in http.StatusCode and message

func Wrap

func Wrap(err error, message string) error

Wrap the error with Error type

Types

type Error

type Error struct {
	// Cause original error
	Cause error `json:"-"`

	// StatusCode for http response code
	StatusCode int `json:"-"`

	// Code is the string convention from https://www.notion.so/w6d/Project-Spec-d1e49d91046b4b61952ecfc135983faf
	Code string `json:"code"`

	// Message from this error
	Message string `json:"message"`
}

Error ...

func GetError

func GetError(err error) *Error

GetError builds or gets the Error type

func (Error) EditCause

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

EditCause returns Error by updating cause

func (Error) EditCode

func (e Error) EditCode(code string) *Error

EditCode returns Error by updating code

func (Error) EditMessage

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

EditMessage returns Error by updating message

func (Error) EditStatusCode

func (e Error) EditStatusCode(statusCode int) *Error

EditStatusCode returns Error by updating status code

func (*Error) Error

func (e *Error) Error() string

Error return a custom message from Error

func (*Error) GetCause

func (e *Error) GetCause() error

GetCause returns the cause from Error

func (*Error) GetMessage

func (e *Error) GetMessage() string

GetMessage returns the message from Error

func (*Error) GetStatusCode

func (e *Error) GetStatusCode() int

GetStatusCode returns the http status code from Error

func (*Error) ShowStack

func (e *Error) ShowStack()

ShowStack prints the stack trace if available

type Interface

type Interface interface {
	// Error type representing an error condition, with the nil value representing no error.
	Error() string

	// GetCause type representing an error condition, with the nil value representing no error.
	GetCause() error

	// GetMessage returns the Message
	GetMessage() string

	// GetStatusCode returns http status code.
	GetStatusCode() int

	// ShowStack prints the stack if exist
	ShowStack()

	// EditCause field from Error struct then return it
	EditCause(error) *Error

	// EditMessage field from Error struct then return it
	EditMessage(string) *Error

	// EditCode field from Error struct then return it
	EditCode(string) *Error

	// EditStatusCode field from Error struct then return it
	EditStatusCode(int) *Error
}

Interface of errorx

Jump to

Keyboard shortcuts

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