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.
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 ¶
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 ¶
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.