errors

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BAD_REQUEST_ERROR = &ErrorResponse{
		[]ErrorObject{
			{
				Status: http.StatusBadRequest,
				Title:  "Bad Request",
			},
		},
	}
	UNAUTHORIZED_ERROR = &ErrorResponse{
		[]ErrorObject{
			{
				Status: http.StatusUnauthorized,
				Title:  "Unauthorized",
			},
		},
	}
	FORBIDDEN_ERROR = &ErrorResponse{
		[]ErrorObject{
			{
				Status: http.StatusForbidden,
				Title:  "Forbidden",
			},
		},
	}
	METHOD_NOT_ALLOWED_ERROR = &ErrorResponse{
		[]ErrorObject{
			{
				Status: http.StatusMethodNotAllowed,
				Title:  "Method Not Allowed",
			},
		},
	}
	INTERNAL_SERVER_ERROR = &ErrorResponse{
		[]ErrorObject{
			{
				Status: http.StatusInternalServerError,
				Title:  "Internal Server Error",
			},
		},
	}
)

Functions

func NewResponseError

func NewResponseError(contents utils.StringerValidator, status int, headers ...http.Header) (err error)

func WriteResponseError

func WriteResponseError(w http.ResponseWriter, err error, fallback ...error)

Types

type ErrorMeta

type ErrorMeta struct {
	Endpoint string `json:"endpoint,omitempty"`
}

type ErrorObject

type ErrorObject struct {
	Status int        `json:"status" validate:"required"`
	Code   string     `json:"code,omitempty"`
	Title  string     `json:"title" validate:"required"`
	Detail string     `json:"detail,omitempty"`
	Meta   *ErrorMeta `json:"meta,omitempty"`
}

type ErrorResponse

type ErrorResponse struct {
	Errors []ErrorObject `json:"errors" validate:"required,dive"`
}

func NewErrorResponse

func NewErrorResponse(status int, title string, other ...string) *ErrorResponse

func (*ErrorResponse) Add

func (res *ErrorResponse) Add(err ErrorObject)

func (*ErrorResponse) String

func (res *ErrorResponse) String() string

func (*ErrorResponse) Validate

func (res *ErrorResponse) Validate() (err error)

type ResponseError

type ResponseError struct {
	Body       string
	Headers    http.Header
	StatusCode int
}

func (ResponseError) Error

func (err ResponseError) Error() (s string)

func (ResponseError) Write

func (err ResponseError) Write(w http.ResponseWriter)

Jump to

Keyboard shortcuts

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