errors

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package errors provides structured, sentinel-based error types for the SaltEdge Go client. All errors implement the standard error interface and support errors.Is / errors.As unwrapping.

Index

Constants

This section is empty.

Variables

View Source
var (
	// 4xx
	ErrBadRequest          = &APIError{StatusCode: http.StatusBadRequest}
	ErrUnauthorized        = &APIError{StatusCode: http.StatusUnauthorized}
	ErrForbidden           = &APIError{StatusCode: http.StatusForbidden}
	ErrNotFound            = &APIError{StatusCode: http.StatusNotFound}
	ErrConflict            = &APIError{StatusCode: http.StatusConflict}
	ErrUnprocessableEntity = &APIError{StatusCode: http.StatusUnprocessableEntity}
	ErrTooManyRequests     = &APIError{StatusCode: http.StatusTooManyRequests}

	// 5xx
	ErrInternalServer = &APIError{StatusCode: http.StatusInternalServerError}
	ErrBadGateway     = &APIError{StatusCode: http.StatusBadGateway}
	ErrServiceUnavail = &APIError{StatusCode: http.StatusServiceUnavailable}

	// Domain-specific (matched by class)
	ErrCustomerNotFound   = &APIError{StatusCode: 404, Class: "CustomerNotFound"}
	ErrConnectionNotFound = &APIError{StatusCode: 404, Class: "ConnectionNotFound"}
	ErrProviderNotFound   = &APIError{StatusCode: 404, Class: "ProviderNotFound"}
	ErrAccountNotFound    = &APIError{StatusCode: 404, Class: "AccountNotFound"}
	ErrConsentNotFound    = &APIError{StatusCode: 404, Class: "ConsentNotFound"}
	ErrPaymentNotFound    = &APIError{StatusCode: 404, Class: "PaymentNotFound"}

	ErrInvalidCredentials   = &APIError{StatusCode: 406, Class: "InvalidCredentials"}
	ErrProviderDisabled     = &APIError{StatusCode: 406, Class: "ProviderDisabled"}
	ErrConnectionDuplicated = &APIError{StatusCode: 409, Class: "ConnectionDuplicated"}
	ErrWrongRequestFormat   = &APIError{StatusCode: 400, Class: "WrongRequestFormat"}
)

Functions

func IsClass

func IsClass(err error, class string) bool

IsClass returns true when err is an APIError with the given class string.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true when err is a 404 APIError.

func IsRateLimit

func IsRateLimit(err error) bool

IsRateLimit returns true when err is a 429 APIError.

func IsRetryable

func IsRetryable(err error) bool

IsRetryable returns true for transient errors that should be retried.

func IsServerError

func IsServerError(err error) bool

IsServerError returns true when err has a 5xx status.

Types

type APIError

type APIError struct {
	StatusCode int    `json:"status_code"`
	Class      string `json:"class"`
	Message    string `json:"message"`
	RequestID  string `json:"request_id,omitempty"`
	Raw        []byte `json:"-"`
}

APIError is returned for all non-2xx HTTP responses from the SaltEdge API.

func NewAPIError

func NewAPIError(statusCode int, body []byte) *APIError

NewAPIError constructs an *APIError from a status code and raw response body.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Is

func (e *APIError) Is(target error) bool

Is supports errors.Is matching by StatusCode (and optionally Class). A sentinel with only StatusCode matches any error with that status. A sentinel with both StatusCode + Class requires both to match.

type DecodeError

type DecodeError struct {
	Body  []byte
	Cause error
}

DecodeError wraps JSON decode failures on API responses.

func (*DecodeError) Error

func (e *DecodeError) Error() string

func (*DecodeError) Unwrap

func (e *DecodeError) Unwrap() error

type NetworkError

type NetworkError struct {
	Cause error
}

NetworkError wraps transport-level failures (DNS, TLS, connect timeout).

func (*NetworkError) Error

func (e *NetworkError) Error() string

func (*NetworkError) Unwrap

func (e *NetworkError) Unwrap() error

type SignatureError

type SignatureError struct {
	Reason string
}

SignatureError is raised when request or webhook signature verification fails.

func (*SignatureError) Error

func (e *SignatureError) Error() string

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError is raised client-side before the request is sent.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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