Documentation
¶
Index ¶
- func GetDefaultInternalServerErrorCode() string
- func GetDefaultInternalServerErrorMessage() string
- func GetErrorIDLength() int
- func IsWithExtraInfoEnabled() bool
- func SetDefaultInternalServerErrorCode(code string)
- func SetDefaultInternalServerErrorMessage(message string)
- func SetErrorIDLength(length int) error
- func SetWithExtraInfo(enabled bool)
- type HTTPError
- func ConvertToHTTPError(err error) (*HTTPError, bool)
- func NewBadRequestError(errorCode string, message string, originalError error, extraInfo any) *HTTPError
- func NewConflictError(errorCode string, message string, originalError error, extraInfo any) *HTTPError
- func NewError(httpCode int, errorCode string, message string, originalError error, ...) *HTTPError
- func NewForbiddenError(errorCode string, message string, originalError error, extraInfo any) *HTTPError
- func NewInternalServerError(errorCode string, message string, originalError error, extraInfo any) *HTTPError
- func NewNotFoundError(errorCode string, message string, originalError error, extraInfo any) *HTTPError
- func NewTooManyRequestsError(errorCode string, message string, originalError error, extraInfo any) *HTTPError
- func NewUnauthorizedError(errorCode string, message string, originalError error, extraInfo any) *HTTPError
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 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 ¶
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 NewConflictError ¶
func NewForbiddenError ¶
func NewInternalServerError ¶
func NewNotFoundError ¶
func NewTooManyRequestsError ¶
func NewUnauthorizedError ¶
func (*HTTPError) MarshalJSON ¶
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.