Help us shape the future of Go! Take the 2026 Go Developer Survey

clienterr

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BadRequest = ClientErrorDefinition{
	// contains filtered or unexported fields
}
View Source
var NotFound = ClientErrorDefinition{
	// contains filtered or unexported fields
}
View Source
var UnprocessableEntity = ClientErrorDefinition{
	// contains filtered or unexported fields
}

Functions

func Response

func Response(c *gin.Context, err error, log *zerolog.Logger)

Response sends the error as a JSON response to the client.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder is a fluent API for building client (4xx) errors.

func (*Builder) Detailed

func (b *Builder) Detailed(errType, detail string, args ...any) *Builder

Detailed changes the error type and adds a detail message.

func (*Builder) Err

func (b *Builder) Err() *errorx.Error

Err returns the client error as an errorx.Error (which also implements error interface).

func (*Builder) Response

func (b *Builder) Response(c *gin.Context, log *zerolog.Logger)

Response sends the client error as a JSON response to the client.

func (*Builder) WithInstance

func (b *Builder) WithInstance(parts ...any) *Builder

WithInstance sets the instance field of the problem details.

func (*Builder) Wrap

func (b *Builder) Wrap(cause error) *Builder

Wrap wraps the provided error as the cause of the client error.

type ClientErrorDefinition

type ClientErrorDefinition struct {
	// contains filtered or unexported fields
}

ClientErrorDefinition is a definition of a client error.

func (ClientErrorDefinition) Detailed

func (c ClientErrorDefinition) Detailed(errType, detail string, args ...any) *Builder

Detailed is a shortcut for creating a new client error with a detailed message.

func (ClientErrorDefinition) New

func (c ClientErrorDefinition) New() *Builder

New creates a new client error builder.

type Mapper

type Mapper interface {
	IfOfType(typeToMatch *errorx.Type) OnMatch
	Finalize() error
	Response(c *gin.Context, log *zerolog.Logger)
}

Mapper is a fluent API for mapping errors to client errors.

func Map

func Map(err error) Mapper

Map creates a new Mapper instance.

type OnMatch

type OnMatch interface {
	Then(errToReturn *Builder) Mapper
}

OnMatch provides a fluent API for defining the response to return when a match is found.

Jump to

Keyboard shortcuts

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