api

package
v1.0.299 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: Apache-2.0 Imports: 5 Imported by: 17

Documentation

Index

Constants

View Source
const (
	ECONFLICT       = "conflict"
	EFORBIDDEN      = "forbidden"
	EINTERNAL       = "internal"
	EINVALID        = "invalid"
	ENOTFOUND       = "not_found"
	ENOTIMPLEMENTED = "not_implemented"
	EUNAUTHORIZED   = "unauthorized"
)

Application error codes.

These are meant to be generic and they map well to HTTP error codes.

Variables

This section is empty.

Functions

func ErrorCode

func ErrorCode(err error) string

ErrorCode unwraps an application error and returns its code. Non-application errors always return EINTERNAL.

func ErrorDebugInfo

func ErrorDebugInfo(err error) string

ErrorDebugInfo unwraps an application error and returns its debug message.

func ErrorMessage

func ErrorMessage(err error) string

ErrorMessage unwraps an application error and returns its message. Non-application errors always return "Internal error".

func ErrorStatusCode

func ErrorStatusCode(code string) int

ErrorStatusCode returns the associated HTTP status code for an application error code.

func WriteError

func WriteError(c echo.Context, err error) error

Types

type Error

type Error struct {
	// Machine-readable error code.
	Code string

	// Human-readable error message.
	Message string

	// DebugInfo contains low-level internal error details that should only be logged.
	// End-users should never see this.
	DebugInfo string
}

Error represents an application-specific error.

func Errorf

func Errorf(code string, format string, args ...any) *Error

Errorf is a helper function to return an Error with a given code and formatted message.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface. Not used by the application otherwise.

func (*Error) WithDebugInfo

func (e *Error) WithDebugInfo(msg string, args ...any) *Error

WithDebugInfo wraps an application error with a debug message.

type HTTPError

type HTTPError struct {
	Error   string `json:"error"`
	Message string `json:"message,omitempty"`
}

type HTTPSuccess

type HTTPSuccess struct {
	Message string `json:"message"`
	Payload any    `json:"payload,omitempty"`
}

Jump to

Keyboard shortcuts

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