errors

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package errors contains helper functions and types to work with errors

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadRequestError

func BadRequestError(err error, message string) error

BadRequestError returns an error with category DataError the error message provided is returned to the user the error object provided is logged in logger

func ConflictError

func ConflictError(err error, message string) error

ConflictError returns an error with category CategoryDataConflict the error message provided is returned to the user the error object provided is logged in logger

func DependencyError

func DependencyError(err error, message string) error

DependencyError returns an error with category CategoryDependencyFailure. Use when a downstream service or store returns an unexpected error. The error message provided is returned to the user. The error object provided is logged in logger.

func ForbiddenError

func ForbiddenError(err error, message string) error

ForbiddenError returns a an error with category CategoryForbidden the error message provided is returned to the user the error object provided is logged in logger

func GeneralError

func GeneralError(err error) error

GeneralError returns a general service error this error mesage sent to the user is "Internal Server Error" the error passed is logged in the logger

func GoneError

func GoneError(err error, message string) error

GoneError returns an error with category CategoryGone (HTTP 410). Use when a resource existed but is no longer available (e.g. expired transfers).

func Is

func Is(err error, cat Category) bool

Is checks that provided error is a ServiceError with desired Category

func IsInternalError

func IsInternalError(err error) bool

IsInternalError checks that provided error is a Internal system error

func NotSupportedError

func NotSupportedError(err error, message string) error

NotSupportedError returns an error with category NotSupported the error message provided is returned to the user the error object provided is logged in logger

func ResourceNotFoundError

func ResourceNotFoundError(err error, message string) error

ResourceNotFoundError returns an error with category ResourceNotFound the error message provided is returned to the user the err object provided is logged in logger

func UnAuthorizedError

func UnAuthorizedError(err error, message string) error

UnAuthorizedError returns an error with category CategoryUnauthorized the error message provided is returned to the user the error object provided is logged in logger

Types

type Category

type Category int

Category defines error category

const (
	// CategoryNoError is for the datadog request tracking, in case if internal services (GRPC) returns no error.
	CategoryNoError Category = iota
	// CategoryDataError The client sends some invalid data in the request,
	// for example, missing or incorrect content in the payload or parameters.
	// Could also represent a generic client error.
	CategoryDataError
	// CategoryUnauthorized The client is not authorized to access the requested resource
	CategoryUnauthorized
	// CategoryForbidden The client is not authenticated to access the requested resource
	CategoryForbidden
	// CategoryResourceNotFound The client is attempting to access a resource that does not exist
	CategoryResourceNotFound
	// CategoryNotSupported The requested functionality is not supported
	CategoryNotSupported
	// CategoryDataConflict The client send some data that can create conflict with existing data
	CategoryDataConflict
	// CategoryLocked The client is not able to access the requested resource due to its locked state
	CategoryLocked
	// CategoryGone The resource existed but is no longer available (e.g. expired)
	CategoryGone
	// CategoryDependencyFailure A dependent service is throwing errors
	CategoryDependencyFailure
	// CategoryGeneralError The service failed in an unexpected way
	CategoryGeneralError
	// CategoryRecovering The service is failing but is expected to recover
	CategoryRecovering
	// CategoryConnectionTimeout Connection to a dependent service timing out
	CategoryConnectionTimeout
)

func (Category) String

func (c Category) String() string

type ServiceError

type ServiceError struct {
	Category Category
	Message  string
	Err      error
}

ServiceError represents service specific type that is used all over the services.

func (ServiceError) Error

func (err ServiceError) Error() string

Error method to comply with error interface

func (ServiceError) ErrorCode

func (err ServiceError) ErrorCode() int

ErrorCode returns the JSON-RPC error code for this error category. This implements the rpc.Error interface from go-ethereum so that ServiceError values are encoded with the correct code in JSON-RPC responses.

func (ServiceError) Is

func (err ServiceError) Is(target error) bool

Is implements the custom condition to check an error is equal to a service error

func (ServiceError) StatusCode

func (err ServiceError) StatusCode() int

StatusCode returns the HTTP status code for the error category

func (ServiceError) Unwrap

func (err ServiceError) Unwrap() error

Unwrap returns the underlying error

Jump to

Keyboard shortcuts

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