Documentation
¶
Index ¶
- func WriteError(w http.ResponseWriter, code ErrorCode, message string, ...)
- func WriteErrorWithDetail(w http.ResponseWriter, code ErrorCode, message string, key string, ...)
- func WriteSimpleError(w http.ResponseWriter, code ErrorCode, message string)
- type ErrorCode
- type ErrorDetail
- type ErrorResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteError ¶
func WriteError(w http.ResponseWriter, code ErrorCode, message string, details map[string]interface{})
WriteError is a convenience function to write an error response in one call.
func WriteErrorWithDetail ¶
func WriteErrorWithDetail(w http.ResponseWriter, code ErrorCode, message string, key string, value interface{})
WriteErrorWithDetail writes an error with a single detail field.
func WriteSimpleError ¶
func WriteSimpleError(w http.ResponseWriter, code ErrorCode, message string)
WriteSimpleError writes an error with no additional details.
Types ¶
type ErrorCode ¶
type ErrorCode string
ErrorCode represents a machine-readable error identifier for frontend error handling.
const ( // Invalid payment proof format or structure ErrCodeInvalidPaymentProof ErrorCode = "invalid_payment_proof" ErrCodeInvalidSignature ErrorCode = "invalid_signature" ErrCodeInvalidTransaction ErrorCode = "invalid_transaction" // Solana transaction verification failures ErrCodeTransactionNotFound ErrorCode = "transaction_not_found" ErrCodeTransactionNotConfirmed ErrorCode = "transaction_not_confirmed" ErrCodeTransactionFailed ErrorCode = "transaction_failed" // Recipient/sender validation failures ErrCodeInvalidRecipient ErrorCode = "invalid_recipient" ErrCodeInvalidSender ErrorCode = "invalid_sender" // Amount/token validation failures ErrCodeAmountBelowMinimum ErrorCode = "amount_below_minimum" ErrCodeAmountMismatch ErrorCode = "amount_mismatch" ErrCodeInsufficientFunds ErrorCode = "insufficient_funds_sol" ErrCodeInsufficientFundsToken ErrorCode = "insufficient_funds_token" ErrCodeInvalidTokenMint ErrorCode = "invalid_token_mint" // SPL transfer validation failures ErrCodeNotSPLTransfer ErrorCode = "not_spl_transfer" ErrCodeMissingTokenAccount ErrorCode = "missing_token_account" ErrCodeInvalidTokenProgram ErrorCode = "invalid_token_program" // Memo/metadata validation failures ErrCodeMissingMemo ErrorCode = "missing_memo" ErrCodeInvalidMemo ErrorCode = "invalid_memo" // Replay protection ErrCodePaymentAlreadyUsed ErrorCode = "payment_already_used" ErrCodeSignatureReused ErrorCode = "signature_reused" // Timeout/expiration errors ErrCodeQuoteExpired ErrorCode = "quote_expired" ErrCodeTransactionExpired ErrorCode = "transaction_expired" )
Payment Verification Errors (x402 spec + Solana-specific)
const ( ErrCodeMissingField ErrorCode = "missing_field" ErrCodeInvalidField ErrorCode = "invalid_field" ErrCodeInvalidAmount ErrorCode = "invalid_amount" ErrCodeInvalidWallet ErrorCode = "invalid_wallet" ErrCodeInvalidResource ErrorCode = "invalid_resource" ErrCodeInvalidCoupon ErrorCode = "invalid_coupon" ErrCodeInvalidCartItem ErrorCode = "invalid_cart_item" ErrCodeEmptyCart ErrorCode = "empty_cart" )
Validation Errors (Request input validation)
const ( ErrCodeResourceNotFound ErrorCode = "resource_not_found" ErrCodeCartNotFound ErrorCode = "cart_not_found" ErrCodeRefundNotFound ErrorCode = "refund_not_found" ErrCodeProductNotFound ErrorCode = "product_not_found" ErrCodeCouponNotFound ErrorCode = "coupon_not_found" ErrCodeSessionNotFound ErrorCode = "session_not_found" ErrCodeCartAlreadyPaid ErrorCode = "cart_already_paid" ErrCodeRefundAlreadyProcessed ErrorCode = "refund_already_processed" )
Resource/State Errors (Resource not found or in wrong state)
const ( ErrCodeCouponExpired ErrorCode = "coupon_expired" ErrCodeCouponUsageLimitReached ErrorCode = "coupon_usage_limit_reached" ErrCodeCouponNotApplicable ErrorCode = "coupon_not_applicable" ErrCodeCouponWrongPaymentMethod ErrorCode = "coupon_wrong_payment_method" )
Coupon-Specific Errors
const ( ErrCodeStripeError ErrorCode = "stripe_error" ErrCodeRPCError ErrorCode = "rpc_error" ErrCodeNetworkError ErrorCode = "network_error" )
External Service Errors (Stripe, RPC, etc.)
const ( ErrCodeInternalError ErrorCode = "internal_error" ErrCodeDatabaseError ErrorCode = "database_error" ErrCodeConfigError ErrorCode = "config_error" )
Internal/System Errors
func (ErrorCode) HTTPStatus ¶
HTTPStatus returns the appropriate HTTP status code for this error.
func (ErrorCode) IsRetryable ¶
IsRetryable returns whether an error code represents a retryable error. Retryable errors are typically transient network/service issues, not validation failures.
type ErrorDetail ¶
type ErrorDetail struct {
Code ErrorCode `json:"code"` // Machine-readable error code
Message string `json:"message"` // Human-readable error message
Retryable bool `json:"retryable"` // Whether the client should retry
Details map[string]interface{} `json:"details,omitempty"` // Optional context (resourceId, etc.)
}
ErrorDetail contains the error code, message, and optional context.
type ErrorResponse ¶
type ErrorResponse struct {
Error ErrorDetail `json:"error"`
}
ErrorResponse is the standardized error format returned to clients. It provides machine-readable error codes for robust error handling.
func NewErrorResponse ¶
func NewErrorResponse(code ErrorCode, message string, details map[string]interface{}) ErrorResponse
NewErrorResponse creates a standardized error response.
func (ErrorResponse) WriteJSON ¶
func (e ErrorResponse) WriteJSON(w http.ResponseWriter)
WriteJSON writes the error response as JSON to the HTTP response writer.