66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package intelligence_finance
|
|
|
|
import "fmt"
|
|
|
|
// ErrorCode represents a numeric error code from the API.
|
|
type ErrorCode int
|
|
|
|
// Predefined error codes.
|
|
const (
|
|
CodeSuccess ErrorCode = 0
|
|
)
|
|
|
|
// APIError represents an error returned by the platform API.
|
|
type APIError struct {
|
|
Code ErrorCode `json:"code"`
|
|
Message string `json:"msg,omitempty"`
|
|
}
|
|
|
|
// Error implements the error interface.
|
|
func (e *APIError) Error() string {
|
|
return fmt.Sprintf("api error: code=%d, msg=%s", e.Code, e.Message)
|
|
}
|
|
|
|
// ErrInvalidResponse is returned when the API response cannot be parsed.
|
|
type ErrInvalidResponse struct {
|
|
Message string
|
|
}
|
|
|
|
// Error implements the error interface.
|
|
func (e *ErrInvalidResponse) Error() string {
|
|
return fmt.Sprintf("invalid response: %s", e.Message)
|
|
}
|
|
|
|
// ErrNetwork is returned when a network error occurs.
|
|
type ErrNetwork struct {
|
|
Err error
|
|
}
|
|
|
|
// Error implements the error interface.
|
|
func (e *ErrNetwork) Error() string {
|
|
return fmt.Sprintf("network error: %v", e.Err)
|
|
}
|
|
|
|
// Unwrap returns the underlying error.
|
|
func (e *ErrNetwork) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
// ErrSigning is returned when a signing error occurs.
|
|
type ErrSigning struct {
|
|
Message string
|
|
Err error
|
|
}
|
|
|
|
// Error implements the error interface.
|
|
func (e *ErrSigning) Error() string {
|
|
if e.Err != nil {
|
|
return fmt.Sprintf("signing error: %s: %v", e.Message, e.Err)
|
|
}
|
|
return fmt.Sprintf("signing error: %s", e.Message)
|
|
}
|
|
|
|
// Unwrap returns the underlying error.
|
|
func (e *ErrSigning) Unwrap() error {
|
|
return e.Err
|
|
} |