httperror

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefaultInternalServerErrorCode

func GetDefaultInternalServerErrorCode() string

func GetDefaultInternalServerErrorMessage

func GetDefaultInternalServerErrorMessage() string

func GetErrorIDLength

func GetErrorIDLength() int

func IsWithExtraInfoEnabled

func IsWithExtraInfoEnabled() bool

func SetDefaultInternalServerErrorCode

func SetDefaultInternalServerErrorCode(code string)

func SetDefaultInternalServerErrorMessage

func SetDefaultInternalServerErrorMessage(message string)

func SetErrorIDLength

func SetErrorIDLength(length int) error

func SetWithExtraInfo

func SetWithExtraInfo(enabled bool)

Types

type HTTPError

type HTTPError struct {
	HTTPStatusCode int    `json:"http_status_code"`
	ErrorCode      string `json:"error_code,omitempty"`
	ErrorID        string `json:"error_id,omitempty"`
	Message        string `json:"message"`
	OriginalError  error  `json:"-"`
	ExtraInfo      any    `json:"extra_info,omitempty"`
}

func ConvertToHTTPError

func ConvertToHTTPError(err error) (*HTTPError, bool)

ConvertToHTTPError attempts to convert a generic error to an *HTTPError. Returns (httpErr, converted) where converted=true means the original error was NOT an *HTTPError and a new one was created to wrap it. The original error is preserved in OriginalError for server-side logging, but is not included in the JSON response.

func NewBadRequestError

func NewBadRequestError(errorCode string, message string, originalError error, extraInfo any) *HTTPError

func NewConflictError

func NewConflictError(errorCode string, message string, originalError error, extraInfo any) *HTTPError

func NewError

func NewError(httpCode int, errorCode string, message string, originalError error, extraInfo any) *HTTPError

func NewForbiddenError

func NewForbiddenError(errorCode string, message string, originalError error, extraInfo any) *HTTPError

func NewInternalServerError

func NewInternalServerError(errorCode string, message string, originalError error, extraInfo any) *HTTPError

func NewNotFoundError

func NewNotFoundError(errorCode string, message string, originalError error, extraInfo any) *HTTPError

func NewTooManyRequestsError

func NewTooManyRequestsError(errorCode string, message string, originalError error, extraInfo any) *HTTPError

func NewUnauthorizedError

func NewUnauthorizedError(errorCode string, message string, originalError error, extraInfo any) *HTTPError

func (*HTTPError) Error

func (e *HTTPError) Error() string

func (*HTTPError) MarshalJSON

func (e *HTTPError) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for HTTPError. This is needed because ExtraInfo is typed as `any`, and certain concrete types stored in the interface (e.g., error, fmt.Stringer, or structs with no exported fields) have no exported fields visible to encoding/json, causing it to produce "{}" instead of a meaningful value. This method normalizes ExtraInfo before serialization to ensure all types produce useful JSON output.

func (*HTTPError) Unwrap

func (e *HTTPError) Unwrap() error

Jump to

Keyboard shortcuts

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