errutil

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InternalServerError = apierror.NewAPIError("INTERNAL_SERVER_ERROR")

InternalServerError represents an internal server error.

Functions

func NewErrorHandler

func NewErrorHandler(
	expectedErrs []ExpectedError) *errorHandler

NewErrorHandler creates a new ErrorHandler.

Parameters:

  • expectedErrs: A slice of ExpectedError objects that define how to handle specific errors.

Returns:

  • *ErrorHandler: A new ErrorHandler.

Types

type APIErrorFactory

type APIErrorFactory struct {
	SystemID string
}

APIErrorFactory is a factory for creating API errors with both the ID and origin set.

func NewErrorFactory

func NewErrorFactory(systemID string) *APIErrorFactory

NewErrorFactory creates a new ErrorFactory for the given system ID.

func (*APIErrorFactory) APIError

APIError creates a new API error with the origin already set.

type ExpectedError

type ExpectedError struct {
	ID         string // The ID of the expected error.
	MaskedID   string // An optional ID to mask the original error ID in the response.
	Status     int    // The HTTP status code to return for this error.
	PublicData bool   // Whether to include the error data in the response.
	Origin     string // The orign of the error.
}

ExpectedError represents an expected error configuration. It defines how to handle specific errors that are anticipated.

func NewExpectedError

func NewExpectedError(id string, status int, origin string) ExpectedError

NewExpectedError creates a new ExpectedError.

Parameters:

  • id: The ID of the expected error.
  • status: The HTTP status code to return for this error.
  • origin: The origin of the error.

Returns:

  • ExpectedError: The new ExpectedError.

func (*ExpectedError) MaskAPIError

func (e *ExpectedError) MaskAPIError(
	apiError apierror.APIError,
) (int, apierror.APIError)

MaskAPIError masks the ID and data of the given API error based on the configuration of the ExpectedError.

Parameters:

  • apiError: The API error to mask.

Returns:

  • int: The HTTP status code to return.
  • *api.APIError: The masked API error.

func (ExpectedError) WithID

func (e ExpectedError) WithID(id string) ExpectedError

WithID returns a new ExpectedError with the given ID.

Parameters:

  • id: The ID to use in the response.

Returns:

  • ExpectedError: The new ExpectedError.

func (ExpectedError) WithMaskedID

func (e ExpectedError) WithMaskedID(maskedID string) ExpectedError

WithMaskedID returns a new ExpectedError with the given masked ID.

Parameters:

  • maskedID: The masked ID to use in the response.

Returns:

  • ExpectedError: The new ExpectedError.

func (ExpectedError) WithOrigin

func (e ExpectedError) WithOrigin(origin string) ExpectedError

WithOrigin returns a new ExpectedError with the given origin.

Parameters:

  • origin: The origin to use in the response.

Returns:

  • ExpectedError: The new ExpectedError.

func (ExpectedError) WithPublicData

func (e ExpectedError) WithPublicData(isPublic bool) ExpectedError

WithPublicData returns a new ExpectedError with the public data flag set.

Returns:

  • ExpectedError: The new ExpectedError.

func (ExpectedError) WithStatus

func (e ExpectedError) WithStatus(status int) ExpectedError

WithStatus returns a new ExpectedError with the given status.

Parameters:

  • status: The status to use in the response.

Returns:

  • ExpectedError: The new ExpectedError.

type ExpectedErrorBuilder

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

ExpectedErrorBuilder is a builder for ExpectedErrors. It can be used to get a list of ExpectedErrors with a system ID.

func NewExpectedErrorBuilder

func NewExpectedErrorBuilder(systemID string) *ExpectedErrorBuilder

NewExpectedErrorBuilder creates a new ExpectedErrorBuilder.

Parameters:

  • systemID: The system ID to add to the errors.

Returns:

  • *ExpectedErrorBuilder: The new ExpectedErrorBuilder.

func (*ExpectedErrorBuilder) Build

Build returns the ExpectedErrors with the system ID.

Returns:

  • ExpectedErrors: The ExpectedErrors with the system ID.

func (*ExpectedErrorBuilder) WithErrors

func (b *ExpectedErrorBuilder) WithErrors(
	errors ExpectedErrors,
) *ExpectedErrorBuilder

With adds errors to the builder.

Parameters:

  • errors: The errors to add.

Returns:

  • *ErrorBuilder: The builder with the errors added.

type ExpectedErrors

type ExpectedErrors []ExpectedError

ExpectedErrors is a slice of ExpectedError.

func GenericErrors

func GenericErrors() ExpectedErrors

GenericErrors returns a list of generic API errors.

Returns:

  • []ExpectedError: A list of generic API errors.

func (ExpectedErrors) GetByID

func (e ExpectedErrors) GetByID(id string) *ExpectedError

GetByID returns the ExpectedError with the given ID, or nil if not found.

Parameters:

  • id: The ID of the expected error.

Returns:

  • *ExpectedError: The ExpectedError with the given ID, or nil if not found.

func (ExpectedErrors) WithErrors

func (e ExpectedErrors) WithErrors(errors ...ExpectedError) ExpectedErrors

WithErrors returns a new slice with the errors appended to the slice.

Parameters:

  • errs: The errors to append.

Returns:

  • ExpectedErrors: The new slice with the errors appended.

func (ExpectedErrors) WithOrigin

func (e ExpectedErrors) WithOrigin(origin string) ExpectedErrors

WithOrigin makes all errors in the slice have the given origin and returns a new slice with the origin set for all errors.

Parameters:

  • origin: The origin to set for all errors.

Returns:

  • ExpectedErrors: The new slice with the origin set for all errors.

Jump to

Keyboard shortcuts

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