Documentation
¶
Overview ¶
Package apperrors defines domain-specific error types and codes for the application. These errors provide more context than standard Go errors and help in mapping internal issues to appropriate JSON-RPC error responses or handling them specifically within the application.
Index ¶
- func MapAppErrorToJSONRPC(err error) (code int, message string, data map[string]interface{})
- func NewAuthError(code ErrorCode, message string, cause error, context map[string]interface{}) error
- func NewInternalError(message string, cause error, context map[string]interface{}) error
- func NewInvalidParamsError(message string, cause error, context map[string]interface{}) error
- func NewInvalidRequestError(message string, cause error, context map[string]interface{}) error
- func NewMethodNotFoundError(message string, cause error, context map[string]interface{}) error
- func NewParseError(message string, cause error, context map[string]interface{}) error
- func NewProtocolError(code ErrorCode, message string, cause error, context map[string]interface{}) error
- func NewResourceError(code ErrorCode, message string, cause error, context map[string]interface{}) error
- func NewServiceNotFoundError(message string, cause error, context map[string]interface{}) error
- type AuthError
- type BaseError
- type ErrorCode
- type InternalError
- type InvalidParamsError
- type InvalidRequestError
- type MethodNotFoundError
- type ParseError
- type ProtocolError
- type ResourceError
- type ServiceNotFoundError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MapAppErrorToJSONRPC ¶
MapAppErrorToJSONRPC translates an application error (or any error) into JSON-RPC components (code, message, data) suitable for a JSON-RPC error response.
func NewAuthError ¶
func NewAuthError(code ErrorCode, message string, cause error, context map[string]interface{}) error
NewAuthError creates a new authentication error.
func NewInternalError ¶
NewInternalError creates a generic internal server error (maps to JSON-RPC -32603).
func NewInvalidParamsError ¶
NewInvalidParamsError creates an error for invalid parameters (maps to JSON-RPC -32602).
func NewInvalidRequestError ¶
NewInvalidRequestError creates an invalid request structure error (maps to JSON-RPC -32600).
func NewMethodNotFoundError ¶
NewMethodNotFoundError creates an error for method not found (maps to JSON-RPC -32601).
func NewParseError ¶
NewParseError creates a JSON parse error (maps to JSON-RPC -32700).
func NewProtocolError ¶
func NewProtocolError(code ErrorCode, message string, cause error, context map[string]interface{}) error
NewProtocolError creates a new API/protocol error.
Types ¶
type AuthError ¶
type AuthError struct{ BaseError }
AuthError represents an authentication or authorization error.
type BaseError ¶
BaseError is the common base for custom application error types.
func (*BaseError) Unwrap ¶
Unwrap returns the underlying error (Cause), enabling errors.Is and errors.As.
func (*BaseError) WithContext ¶
WithContext adds a key-value pair to the error's context map. It initializes the map if necessary and returns the modified error pointer for chaining.
type ErrorCode ¶
type ErrorCode int
ErrorCode defines domain-specific error codes.
const ( // --- Auth Errors (1000-1999) ---. // Consistent with general authentication concepts. ErrAuthFailure ErrorCode = 1000 + iota ErrAuthExpired ErrAuthInvalid ErrAuthMissing // --- Resource Errors (3000-3999) ---. // Consistent with general resource access concepts. ErrResourceNotFound ErrorCode = 3000 + iota ErrResourceForbidden ErrResourceInvalid // --- API/Protocol Errors (4000-4999 & JSON-RPC range) ---. // For errors related to the application's API or general protocol handling. ErrProtocolInvalid ErrorCode = 4000 + iota // e.g., malformed API request beyond basic parsing ErrProtocolUnsupported // e.g., trying to use an unsupported version or feature // JSON-RPC Standard Codes mapped to our ErrorCode type. // These are standard and highly relevant for any JSON-RPC style API. ErrParseError ErrorCode = -32700 // JSONRPCParseError ErrInvalidRequest ErrorCode = -32600 // JSONRPCInvalidRequest ErrMethodNotFound ErrorCode = -32601 // JSONRPCMethodNotFound ErrInvalidParams ErrorCode = -32602 // JSONRPCInvalidParams ErrInternalError ErrorCode = -32603 // JSONRPCInternalError // Custom server-defined API/application errors within the recommended JSON-RPC range (-32000 to -32099). ErrRequestSequence ErrorCode = -32001 // Invalid message sequence for current state (if state matters) ErrServiceNotFound ErrorCode = -32002 // Specific internal error when a required internal service/component lookup fails )
Domain-specific error codes.
type InternalError ¶
type InternalError struct{ BaseError }
InternalError represents a generic internal server error, aligning with JSON-RPC.
type InvalidParamsError ¶
type InvalidParamsError struct{ BaseError }
InvalidParamsError represents an error due to invalid method parameters, aligning with JSON-RPC.
type InvalidRequestError ¶
type InvalidRequestError struct{ BaseError }
InvalidRequestError represents an invalid JSON-RPC request structure error, aligning with JSON-RPC.
type MethodNotFoundError ¶
type MethodNotFoundError struct{ BaseError }
MethodNotFoundError represents an error when a requested method is not found, aligning with JSON-RPC.
type ParseError ¶
type ParseError struct{ BaseError }
ParseError represents a JSON parsing error, aligning with JSON-RPC.
type ProtocolError ¶
type ProtocolError struct{ BaseError }
ProtocolError represents a violation of the application's API protocol rules or structure.
type ResourceError ¶
type ResourceError struct{ BaseError }
ResourceError represents an error related to accessing or manipulating an application resource.
type ServiceNotFoundError ¶
type ServiceNotFoundError struct{ BaseError }
ServiceNotFoundError represents an error when a required internal service/component cannot be found.