errors

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package errors provides comprehensive error handling for the auth module. It defines error types and provides context-aware error handling.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidToken is returned when a token is invalid
	ErrInvalidToken = errors.New("invalid token")

	// ErrExpiredToken is returned when a token has expired
	ErrExpiredToken = errors.New("token expired")

	// ErrMissingToken is returned when a token is missing
	ErrMissingToken = errors.New("token missing")

	// ErrInvalidSignature is returned when a token has an invalid signature
	ErrInvalidSignature = errors.New("invalid token signature")

	// ErrInvalidClaims is returned when a token has invalid claims
	ErrInvalidClaims = errors.New("invalid token claims")

	// ErrUnauthorized is returned when a user is not authorized to perform an operation
	ErrUnauthorized = errors.New("unauthorized")

	// ErrForbidden is returned when a user is forbidden from performing an operation
	ErrForbidden = errors.New("forbidden")

	// ErrInvalidConfig is returned when the configuration is invalid
	ErrInvalidConfig = errors.New("invalid configuration")

	// ErrInternal is returned when an internal error occurs
	ErrInternal = errors.New("internal error")

	// ErrNotImplemented is returned when a feature is not implemented
	ErrNotImplemented = errors.New("not implemented")
)

Standard error types

Functions

func GetContext

func GetContext(err error, key string) (interface{}, bool)

GetContext gets a context value from an error

func GetMessage

func GetMessage(err error) (string, bool)

GetMessage gets the message from an error

func GetOp

func GetOp(err error) (string, bool)

GetOp gets the operation from an error

func WithContext

func WithContext(err error, key string, value interface{}) error

WithContext adds context to an error

func WithMessage

func WithMessage(err error, message string) error

WithMessage adds a message to an error

func WithOp

func WithOp(err error, op string) error

WithOp adds an operation to an error

func Wrap

func Wrap(err error, message string) error

Wrap wraps an error with a message

Types

type AuthError

type AuthError struct {
	// Err is the underlying error
	Err error

	// Op is the operation that caused the error
	Op string

	// Message is a human-readable message
	Message string

	// Context contains additional context for the error
	Context map[string]interface{}
}

AuthError represents an authentication or authorization error with context

func NewAuthError

func NewAuthError(err error, op string, message string, context map[string]interface{}) *AuthError

NewAuthError creates a new AuthError

func (*AuthError) Error

func (e *AuthError) Error() string

Error implements the error interface

func (*AuthError) Is

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

Is reports whether the error is of the target type

func (*AuthError) Unwrap

func (e *AuthError) Unwrap() error

Unwrap returns the underlying error

Jump to

Keyboard shortcuts

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