http

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHTTPErrorMapper

func RegisterHTTPErrorMapper(m HTTPErrorMapper)

RegisterHTTPErrorMapper registers a domain-specific error mapper. Domains call this from init() to contribute their error mappings.

Types

type APIError added in v0.0.2

type APIError struct {
	Message string    `json:"message"`
	Code    ErrorCode `json:"code"`
	// contains filtered or unexported fields
}

APIError represents a response we might send to the User in the event of an error.

func (*APIError) AsError added in v0.0.2

func (e *APIError) AsError() error

AsError returns the error message.

func (*APIError) Error added in v0.0.2

func (e *APIError) Error() string

Error returns the error message.

type APIResponse added in v0.0.2

type APIResponse[T any] struct {
	Data       T                     `json:"data,omitempty"`
	Pagination *filtering.Pagination `json:"pagination,omitempty"`
	Error      *APIError             `json:"error,omitempty"`
	Details    ResponseDetails       `json:"details"`
	// contains filtered or unexported fields
}

APIResponse represents a response we might send to the user.

func NewAPIErrorResponse added in v0.0.2

func NewAPIErrorResponse(issue string, code ErrorCode, details ResponseDetails) *APIResponse[any]

NewAPIErrorResponse returns a new APIResponse with an error field.

type ErrorCode added in v0.0.2

type ErrorCode string

ErrorCode is a string code identifying specific error conditions in API responses.

const (
	// ErrNothingSpecific is a catch-all error code for when we just need one.
	ErrNothingSpecific ErrorCode = "E100"
	// ErrFetchingSessionContextData is returned when we fail to fetch session context data.
	ErrFetchingSessionContextData ErrorCode = "E101"
	// ErrDecodingRequestInput is returned when we fail to decode request input.
	ErrDecodingRequestInput ErrorCode = "E102"
	// ErrValidatingRequestInput is returned when the user provides invalid input.
	ErrValidatingRequestInput ErrorCode = "E103"
	// ErrDataNotFound is returned when we fail to find data in the database.
	ErrDataNotFound ErrorCode = "E104"
	// ErrTalkingToDatabase is returned when we fail to interact with a database.
	ErrTalkingToDatabase ErrorCode = "E105"
	// ErrMisbehavingDependency is returned when we fail to interact with a third party.
	ErrMisbehavingDependency ErrorCode = "E106"
	// ErrTalkingToSearchProvider is returned when we fail to interact with the search provider.
	ErrTalkingToSearchProvider ErrorCode = "E107"
	// ErrSecretGeneration is returned when a user is not authorized.
	ErrSecretGeneration ErrorCode = "E108"
	// ErrUserIsBanned is returned when a user is banned.
	ErrUserIsBanned ErrorCode = "E109"
	// ErrUserIsNotAuthorized is returned when a user is not authorized.
	ErrUserIsNotAuthorized ErrorCode = "E110"
	// ErrEncryptionIssue is returned when encryption fails in the service.
	ErrEncryptionIssue ErrorCode = "E111"
	// ErrCircuitBroken is returned when a service is circuit broken.
	ErrCircuitBroken ErrorCode = "E112"
)

func ToAPIError

func ToAPIError(err error) (code ErrorCode, msg string)

ToAPIError maps known sentinel errors to ErrorCode and a safe user-facing message. It tries PlatformMapper first, then each registered domain mapper. Returns (code, message). Use ErrTalkingToDatabase and "an error occurred" as fallback for unknown errors.

type HTTPErrorMapper

type HTTPErrorMapper interface {
	Map(err error) (code ErrorCode, msg string, ok bool)
}

HTTPErrorMapper maps domain errors to (ErrorCode, message). ok=false means no match.

var PlatformMapper HTTPErrorMapper = platformMapper{}

PlatformMapper maps platform-level errors to HTTP error codes and messages. It does not depend on any domain.

type ResponseDetails added in v0.0.2

type ResponseDetails struct {
	CurrentAccountID string `json:"currentAccountID"`
	TraceID          string `json:"traceID"`
	// contains filtered or unexported fields
}

ResponseDetails represents details about the response.

Jump to

Keyboard shortcuts

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