errors

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package errors provides a way to create and handle errors with types and messages. Errors from this package are used to set the status code of API responses based on the Type of the Error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Wrapped error
	Type    Type
	Message string
}

Error represents an error with a type and a message. It wraps the original error if one is provided.

func New

func New(ty Type, wrapped error, msg string, args ...any) *Error

New creates a new error with the given type, wrapped error, message and arguments. The message is formatted using fmt.Sprintf with the provided arguments.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(target error) bool

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Type

type Type = uint8

Type represents the type of error. It should represent the status code that should be returned in the API response.

const (
	// TypeUnknown is used when the error type is not known.
	TypeUnknown Type = iota
	// TypeBadRequest is used when the request is invalid.
	TypeBadRequest
	// TypeNotFound is used when the requested resource is not found.
	TypeNotFound
	// TypeUnauthorized is used when the request is not authorized.
	TypeUnauthorized
	// TypeForbidden is used when the request is forbidden.
	TypeForbidden
)

Jump to

Keyboard shortcuts

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