errors

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package errors provides standardized error types for the Service Layer.

Index

Constants

View Source
const (
	CodeInvalidParameter = "INVALID_PARAMETER"
	CodeMissingParameter = "MISSING_PARAMETER"
	CodeInvalidFormat    = "INVALID_FORMAT"
	CodeInvalidState     = "INVALID_STATE"
)

Error codes - Input Validation Errors

View Source
const (
	CodeUnauthorized       = "UNAUTHORIZED"
	CodeInvalidCredentials = "INVALID_CREDENTIALS"
	CodeTokenExpired       = "TOKEN_EXPIRED"
	CodePermissionDenied   = "PERMISSION_DENIED"
)

Error codes - Authentication and Authorization Errors

View Source
const (
	CodeResourceNotFound      = "RESOURCE_NOT_FOUND"
	CodeResourceAlreadyExists = "RESOURCE_ALREADY_EXISTS"
	CodeResourceConflict      = "RESOURCE_CONFLICT"
)

Error codes - Resource Errors

View Source
const (
	CodeInternalError         = "INTERNAL_ERROR"
	CodeDatabaseError         = "DATABASE_ERROR"
	CodeBlockchainError       = "BLOCKCHAIN_ERROR"
	CodeServiceUnavailable    = "SERVICE_UNAVAILABLE"
	CodeRateLimitExceeded     = "RATE_LIMIT_EXCEEDED"
	CodeAPIDeprecated         = "API_DEPRECATED"
	CodeAPIVersionUnsupported = "API_VERSION_UNSUPPORTED"
)

Error codes - Service Errors

View Source
const (
	CodeExecutionTimeout     = "EXECUTION_TIMEOUT"
	CodeMemoryLimitExceeded  = "MEMORY_LIMIT_EXCEEDED"
	CodeSandboxViolation     = "SANDBOX_VIOLATION"
	CodeSecretAccessDenied   = "SECRET_ACCESS_DENIED"
	CodeFunctionCompileError = "FUNCTION_COMPILE_ERROR"
	CodeFunctionRuntimeError = "FUNCTION_RUNTIME_ERROR"
)

Error codes - TEE-Specific Errors

View Source
const (
	CodeTxVerificationFailed    = "TX_VERIFICATION_FAILED"
	CodeContractExecutionFailed = "CONTRACT_EXECUTION_FAILED"
	CodeInsufficientGas         = "INSUFFICIENT_GAS"
	CodeNetworkFeeTooLow        = "NETWORK_FEE_TOO_LOW"
)

Error codes - Blockchain-Specific Errors

Variables

This section is empty.

Functions

This section is empty.

Types

type ServiceError

type ServiceError struct {
	Code      string                 `json:"code"`
	Message   string                 `json:"message"`
	Details   map[string]interface{} `json:"details,omitempty"`
	HTTPCode  int                    `json:"-"` // Not serialized in JSON responses
	RequestID string                 `json:"requestId,omitempty"`
}

ServiceError represents a standardized error returned by the service.

func FromError

func FromError(err error) *ServiceError

FromError converts a standard error to a ServiceError. If the error is already a ServiceError, it is returned as is.

func NewAPIDeprecatedError

func NewAPIDeprecatedError(version string, sunsetDate string) *ServiceError

NewAPIDeprecatedError creates a new API deprecated error.

func NewAPIVersionUnsupportedError

func NewAPIVersionUnsupportedError(requestedVersion string, supportedVersions []string) *ServiceError

NewAPIVersionUnsupportedError creates a new API version unsupported error.

func NewBlockchainError

func NewBlockchainError(operation string, err error) *ServiceError

NewBlockchainError creates a new blockchain error.

func NewContractExecutionFailedError

func NewContractExecutionFailedError(contractHash, operation, reason string) *ServiceError

NewContractExecutionFailedError creates a new contract execution failed error.

func NewDatabaseError

func NewDatabaseError(operation string, err error) *ServiceError

NewDatabaseError creates a new database error.

func NewExecutionTimeoutError

func NewExecutionTimeoutError(functionID string, timeout int) *ServiceError

NewExecutionTimeoutError creates a new execution timeout error.

func NewFunctionCompileError

func NewFunctionCompileError(functionID string, errors []string) *ServiceError

NewFunctionCompileError creates a new function compile error.

func NewFunctionRuntimeError

func NewFunctionRuntimeError(functionID string, errorMessage string, stackTrace string) *ServiceError

NewFunctionRuntimeError creates a new function runtime error.

func NewInsufficientGasError

func NewInsufficientGasError(required, available int64) *ServiceError

NewInsufficientGasError creates a new insufficient gas error.

func NewInternalError

func NewInternalError(message string) *ServiceError

NewInternalError creates a new internal error.

func NewInvalidCredentialsError

func NewInvalidCredentialsError() *ServiceError

NewInvalidCredentialsError creates a new invalid credentials error.

func NewInvalidFormatError

func NewInvalidFormatError(message string) *ServiceError

NewInvalidFormatError creates a new invalid format error.

func NewInvalidParameterError

func NewInvalidParameterError(paramName, reason string) *ServiceError

NewInvalidParameterError creates a new invalid parameter error.

func NewInvalidStateError

func NewInvalidStateError(message string) *ServiceError

NewInvalidStateError creates a new invalid state error.

func NewMemoryLimitExceededError

func NewMemoryLimitExceededError(functionID string, limit int) *ServiceError

NewMemoryLimitExceededError creates a new memory limit exceeded error.

func NewMissingParameterError

func NewMissingParameterError(paramName string) *ServiceError

NewMissingParameterError creates a new missing parameter error.

func NewNetworkFeeTooLowError

func NewNetworkFeeTooLowError(required, provided int64) *ServiceError

NewNetworkFeeTooLowError creates a new network fee too low error.

func NewPermissionDeniedError

func NewPermissionDeniedError(resource, action string) *ServiceError

NewPermissionDeniedError creates a new permission denied error.

func NewRateLimitExceededError

func NewRateLimitExceededError(limit int, timeWindow string) *ServiceError

NewRateLimitExceededError creates a new rate limit exceeded error.

func NewResourceAlreadyExistsError

func NewResourceAlreadyExistsError(resourceType, resourceID string) *ServiceError

NewResourceAlreadyExistsError creates a new resource already exists error.

func NewResourceConflictError

func NewResourceConflictError(resourceType, resourceID, reason string) *ServiceError

NewResourceConflictError creates a new resource conflict error.

func NewResourceNotFoundError

func NewResourceNotFoundError(resourceType, resourceID string) *ServiceError

NewResourceNotFoundError creates a new resource not found error.

func NewSandboxViolationError

func NewSandboxViolationError(functionID, violation string) *ServiceError

NewSandboxViolationError creates a new sandbox violation error.

func NewSecretAccessDeniedError

func NewSecretAccessDeniedError(functionID, secretName string) *ServiceError

NewSecretAccessDeniedError creates a new secret access denied error.

func NewServiceUnavailableError

func NewServiceUnavailableError(reason string) *ServiceError

NewServiceUnavailableError creates a new service unavailable error.

func NewTokenExpiredError

func NewTokenExpiredError() *ServiceError

NewTokenExpiredError creates a new token expired error.

func NewTxVerificationFailedError

func NewTxVerificationFailedError(reason string) *ServiceError

NewTxVerificationFailedError creates a new transaction verification failed error.

func NewUnauthorizedError

func NewUnauthorizedError() *ServiceError

NewUnauthorizedError creates a new unauthorized error.

func (*ServiceError) Error

func (e *ServiceError) Error() string

Error implements the error interface.

func (*ServiceError) ToResponse

func (e *ServiceError) ToResponse() map[string]interface{}

ToResponse converts a ServiceError to a standardized API response.

func (*ServiceError) WithDetailField

func (e *ServiceError) WithDetailField(key string, value interface{}) *ServiceError

WithDetailField adds a single detail field to the error.

func (*ServiceError) WithDetails

func (e *ServiceError) WithDetails(details map[string]interface{}) *ServiceError

WithDetails adds details to the error.

func (*ServiceError) WithRequestID

func (e *ServiceError) WithRequestID(requestID string) *ServiceError

WithRequestID adds a request ID to the error.

Jump to

Keyboard shortcuts

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