apierror

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2025 License: Apache-2.0 Imports: 2 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError interface {
	Error() string
	ID() string
	Data() any
	Message() string
	Origin() string
}

APIError represents a custom error type.

type DefaultAPIError

type DefaultAPIError struct {
	ErrID      string `json:"id"`
	ErrData    any    `json:"data,omitempty"`
	ErrMessage string `json:"message,omitempty"`
	ErrOrigin  string `json:"origin,omitempty"`
}

DefaultAPIError represents a JSON marshalable custom error type.

func APIErrorFrom

func APIErrorFrom(err APIError) *DefaultAPIError

APIErrorFrom converts an APIError to a DefaultAPIError.

Parameters:

  • err: The APIError to convert.

Returns:

  • *defaultAPIError: A new defaultAPIError instance.

func NewAPIError

func NewAPIError(id string) *DefaultAPIError

NewAPIError returns a new error with the given ID.

Parameters:

  • id: The ID of the error.

Returns:

  • *defaultAPIError: A new defaultAPIError instance.

func (*DefaultAPIError) Data

func (e *DefaultAPIError) Data() any

Data returns the data associated with the error.

Returns:

  • any: The data associated with the error.

func (*DefaultAPIError) Error

func (e *DefaultAPIError) Error() string

Error returns the full error message as a string. If the error has a message, it returns the ID followed by the message. Otherwise, it returns just the ID.

Returns:

  • string: The full error message as a string.

func (*DefaultAPIError) ID

func (e *DefaultAPIError) ID() string

ID returns the ID of the error.

Returns:

  • string: The ID of the error.

func (*DefaultAPIError) MarshalJSON

func (e *DefaultAPIError) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling.

Returns:

  • []byte: The JSON representation of the error.
  • error: An error if the marshaling fails.

func (*DefaultAPIError) Message

func (e *DefaultAPIError) Message() string

Message returns the message associated with the error.

Returns:

  • string: The message associated with the error.

func (*DefaultAPIError) Origin

func (e *DefaultAPIError) Origin() string

Origin returns the origin associated with the error.

Returns:

  • string: The origin associated with the error.

func (*DefaultAPIError) UnmarshalJSON

func (e *DefaultAPIError) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling.

Parameters:

  • data: The JSON data to unmarshal.

Returns:

  • error: An error if the unmarshaling fails.

func (*DefaultAPIError) WithData

func (e *DefaultAPIError) WithData(data any) *DefaultAPIError

WithData returns a new error with the given data.

Parameters:

  • data: The data to include in the error.

Returns:

  • *defaultAPIError: A new defaultAPIError.

func (*DefaultAPIError) WithID

func (e *DefaultAPIError) WithID(id string) *DefaultAPIError

WithID returns a new error with the given ID.

Parameters:

  • id: The ID to include in the error.

Returns:

  • *defaultAPIError: A new defaultAPIError.

func (*DefaultAPIError) WithMessage

func (e *DefaultAPIError) WithMessage(message string) *DefaultAPIError

WithMessage returns a new error with the given message.

Parameters:

  • message: The message to include in the error.

Returns:

  • *defaultAPIError: A new defaultAPIError.

func (*DefaultAPIError) WithOrigin

func (e *DefaultAPIError) WithOrigin(origin string) *DefaultAPIError

WithMessage returns a new error with the given origin.

Parameters:

  • message: The message to include in the error.

Returns:

  • *defaultAPIError: A new defaultAPIError.

Jump to

Keyboard shortcuts

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