errors

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppError

type AppError struct {
	Code    int    // HTTP status code (e.g., 404, 500)
	Message string // User-facing safe message
	Err     error  // Internal error (logged, never exposed in production)
}

AppError represents a structured application error with HTTP status context.

func BadRequest

func BadRequest(message string) *AppError

BadRequest creates a 400 error.

func Conflict

func Conflict(message string) *AppError

Conflict creates a 409 error.

func Forbidden

func Forbidden(message string) *AppError

Forbidden creates a 403 error.

func Internal

func Internal(err error) *AppError

Internal creates a 500 error wrapping an internal error.

func NotFound

func NotFound(message string) *AppError

NotFound creates a 404 error.

func Unauthorized

func Unauthorized(message string) *AppError

Unauthorized creates a 401 error.

func Unprocessable

func Unprocessable(message string) *AppError

Unprocessable creates a 422 error.

func (*AppError) Error

func (e *AppError) Error() string

Error returns the user-facing message. Implements the error interface.

func (*AppError) ErrorResponse

func (e *AppError) ErrorResponse() map[string]any

ErrorResponse returns a map for JSON error responses. In debug mode, it includes internal error details. In production, only the safe message.

func (*AppError) Unwrap

func (e *AppError) Unwrap() error

Unwrap returns the underlying error for errors.Is/As support.

Jump to

Keyboard shortcuts

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