errmap

package
v0.0.0-...-110f058 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Friendly

func Friendly(err error) string

Friendly returns a user-friendly, action-oriented message string. It uses request context (method/URL) when available, and produces clearer phrasing than the raw error text.

func Map

func Map(err error) error

Map converts an arbitrary error into an *Error with a best-effort code. It keeps the original error as the cause.

func MapRequestError

func MapRequestError(method, urlStr string, err error) error

MapRequestError annotates the mapped error with request context.

func ToJSON

func ToJSON(err error) string

ToJSON marshals an error into {"code":"...","message":"..."}. If err is not an *Error, code defaults to "unknown".

Types

type Code

type Code string

Code classifies high-level error categories for user-facing messages.

const (
	CodeCanceled            Code = "canceled"
	CodeTimeout             Code = "timeout"
	CodeDNSError            Code = "dns_error"
	CodeInvalidURL          Code = "invalid_url"
	CodeUnsupportedScheme   Code = "unsupported_scheme"
	CodeConnectionRefused   Code = "connection_refused"
	CodeConnectionReset     Code = "connection_reset"
	CodeNetworkUnreachable  Code = "network_unreachable"
	CodeTLSUnknownAuthority Code = "tls_unknown_authority"
	CodeTLSHostnameMismatch Code = "tls_hostname_mismatch"
	CodeTLSHandshake        Code = "tls_handshake"
	CodeIO                  Code = "io_error"
	CodeUnexpected          Code = "unexpected"
	CodeExpressionSyntax    Code = "expression_syntax"
	CodeExpressionRuntime   Code = "expression_runtime"
)

type Error

type Error struct {
	Code      Code
	Message   string
	Method    string
	URL       string
	Temporary bool
	Retryable bool
	// contains filtered or unexported fields
}

Error is a small, idiomatic wrapper that carries a code and context while preserving the original cause via Unwrap.

func New

func New(code Code, message string, cause error) *Error

New constructs an Error with the supplied code, message, and underlying cause.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Jump to

Keyboard shortcuts

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