xerr

package module
v0.0.0-...-25f7f3c Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2024 License: MIT Imports: 5 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ServerError = New(500, "ServerError",
	"There was an issue on the server side. Please report to us or try again later.")

ServerError always the same

Functions

func Is

func Is(err error, key string) bool

Is err the instance of Error,and has <key>?

func IsClientError

func IsClientError(err error) bool

func IsCode

func IsCode(err error, code int) bool

IsCode check if the status code is <code>

Types

type Error

type Error struct {
	Key     string `json:"error"`
	Message string `json:"message"`
	// contains filtered or unexported fields
}

Error custom struct

func As

func As(err error) (*Error, bool)

func New

func New(code int, key string, msg string) *Error

New Error

func Newf

func Newf(code int, key string, format string, a ...interface{}) *Error

Newf create an Error use format

func ParseResp

func ParseResp(resp *http.Response) *Error

ParseResp can parse http response, if there is a error, it would read and close the body for error messages.

func (*Error) Error

func (e *Error) Error() string

Error makes it compatible with `error` interface.

func (*Error) StatusCode

func (e *Error) StatusCode() int

StatusCode is http status code

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap support the Unwrap interface

Jump to

Keyboard shortcuts

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