Documentation
¶
Overview ¶
Package httperror defines HTTP error types.
Index ¶
- Constants
- func NewHTTPErrorStringBuilder(e HTTPError) *strings.Builder
- type HTTPError
- func NewAlreadyExistsError(errors ...ValidationError) *HTTPError
- func NewBadRequestError(errors ...ValidationError) *HTTPError
- func NewBusinessRuleViolationError(errors ...ValidationError) *HTTPError
- func NewForbiddenError(errors ...ValidationError) *HTTPError
- func NewHTTPError(httpStatus int, detail string) *HTTPError
- func NewHTTPErrorFromResponse(resp *http.Response) *HTTPError
- func NewHTTPValidationError(errors ...ValidationError) *HTTPError
- func NewInvalidBodyPropertyFormatError(errors ...ValidationError) *HTTPError
- func NewInvalidBodyPropertyValueError(errors ...ValidationError) *HTTPError
- func NewInvalidRequestHeaderFormatError(errors ...ValidationError) *HTTPError
- func NewInvalidRequestParameterFormatError(errors ...ValidationError) *HTTPError
- func NewInvalidRequestParameterValueError(errors ...ValidationError) *HTTPError
- func NewLicenseCancelledError(errors ...ValidationError) *HTTPError
- func NewLicenseExpiredError(errors ...ValidationError) *HTTPError
- func NewMissingBodyPropertyError(errors ...ValidationError) *HTTPError
- func NewMissingRequestHeaderError(errors ...ValidationError) *HTTPError
- func NewMissingRequestParameterError(errors ...ValidationError) *HTTPError
- func NewNotFoundError(errors ...ValidationError) *HTTPError
- func NewServerError(errors ...ValidationError) *HTTPError
- func NewServiceUnavailableError(errors ...ValidationError) *HTTPError
- func NewUnauthorizedError(errors ...ValidationError) *HTTPError
- type ValidationError
Constants ¶
const MaxPostCloseReadBytes int64 = 256 << 10
MaxPostCloseReadBytes is the max number of bytes that a client is willing to read when draining any unread bytes from the response body as part of closing the response, before the body itself is closed. This threshold matches the commonly used small-body drain limit for preserving HTTP connection reuse.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HTTPError ¶
type HTTPError struct {
// A URI reference that identifies the problem type.
Type string `json:"type,omitempty"`
// The HTTP status code generated by the origin server for this occurrence of the problem.
Status int `json:"status,omitempty"`
// A short, human-readable summary of the problem type.
Title string `json:"title,omitempty"`
// A human-readable explanation specific to this occurrence of the problem.
Detail string `json:"detail,omitempty"`
// A URI reference that identifies the specific occurrence of the problem.
// It may or may not yield further information if dereferenced.
Instance string `json:"instance,omitempty"`
// An API specific error code aiding the provider team understand the error based on their own potential taxonomy or registry.
Code string `json:"code,omitempty"`
// An array of error details to accompany a problem details response.
Errors []ValidationError `json:"errors,omitempty"`
}
HTTPError is the data structure of an HTTP error that follows the RFC 9457 specification. The schema is inspired by Swagger API specification.
func NewAlreadyExistsError ¶
func NewAlreadyExistsError(errors ...ValidationError) *HTTPError
NewAlreadyExistsError creates an error that occurs when the resource being created is found to already exist on the server.
func NewBadRequestError ¶
func NewBadRequestError(errors ...ValidationError) *HTTPError
NewBadRequestError creates an error that occurs when the server cannot or will not process the request due to something that is perceived to be a client error (for example, malformed request syntax, invalid request message framing, or deceptive request routing). Your client application initiated a request that is malformed. Please review your client request against the defined semantics for the API.
func NewBusinessRuleViolationError ¶
func NewBusinessRuleViolationError(errors ...ValidationError) *HTTPError
NewBusinessRuleViolationError occurs when the request is deemed unprocessable. Your client issued a request that failed business rule validation. Please review your request to determine if you can remain within appropriate business rules. Consider validating your request against available metadata (e.g. schemas) prior to sending to the server.
func NewForbiddenError ¶
func NewForbiddenError(errors ...ValidationError) *HTTPError
NewForbiddenError creates an error that occurs when the requested resource (and/or operation combination) is not authorized for the requesting client (and or authorization context). Your client application tried to perform an operation on a resource that it’s not authorized to perform in the given context.
func NewHTTPError ¶
NewHTTPError creates an HTTPError instance with status.
func NewHTTPErrorFromResponse ¶
NewHTTPErrorFromResponse creates an HTTPError from an HTTP response.
func NewHTTPValidationError ¶
func NewHTTPValidationError(errors ...ValidationError) *HTTPError
NewHTTPValidationError occurs when the request is deemed unprocessable.
func NewInvalidBodyPropertyFormatError ¶
func NewInvalidBodyPropertyFormatError(errors ...ValidationError) *HTTPError
NewInvalidBodyPropertyFormatError occurs when the request body contains a malformed property.
func NewInvalidBodyPropertyValueError ¶
func NewInvalidBodyPropertyValueError(errors ...ValidationError) *HTTPError
NewInvalidBodyPropertyValueError occurs when the request body contains an invalid property value.
func NewInvalidRequestHeaderFormatError ¶
func NewInvalidRequestHeaderFormatError(errors ...ValidationError) *HTTPError
NewInvalidRequestHeaderFormatError occurs when the request contains a malformed request header. Your client issued a request that contained a malformed request header. Please review your request parameters and compare against the shared API definition when applicable. Consider validating your headers against the published schema or API definition metadata prior to sending to the server.
func NewInvalidRequestParameterFormatError ¶
func NewInvalidRequestParameterFormatError(errors ...ValidationError) *HTTPError
NewInvalidRequestParameterFormatError occurs when the request contains a malformed query or path parameter. Your client issued a request that contained a malformed query or path parameter. Please review your request parameters and compare against the shared API definition. Consider validating your parameters published schema prior to sending to the server.
func NewInvalidRequestParameterValueError ¶
func NewInvalidRequestParameterValueError(errors ...ValidationError) *HTTPError
NewInvalidRequestParameterValueError occurs when the request contains an invalid query or path parameter value.
func NewLicenseCancelledError ¶
func NewLicenseCancelledError(errors ...ValidationError) *HTTPError
NewLicenseCancelledError creates an error that occurs when the license associated with the client has been cancelled thus rendering the service unavailable.
func NewLicenseExpiredError ¶
func NewLicenseExpiredError(errors ...ValidationError) *HTTPError
NewLicenseExpiredError creates an error that occurs when the license associated with the client has expired thus rendering the service unavailable.
func NewMissingBodyPropertyError ¶
func NewMissingBodyPropertyError(errors ...ValidationError) *HTTPError
NewMissingBodyPropertyError creates a missing body property error. This problem occurs when the request sent to the API is missing an expected body property.
func NewMissingRequestHeaderError ¶
func NewMissingRequestHeaderError(errors ...ValidationError) *HTTPError
NewMissingRequestHeaderError occurs when the request sent to the API is missing an expected request header.
func NewMissingRequestParameterError ¶
func NewMissingRequestParameterError(errors ...ValidationError) *HTTPError
NewMissingRequestParameterError occurs when the request sent to the API is missing a query or path parameter.
func NewNotFoundError ¶
func NewNotFoundError(errors ...ValidationError) *HTTPError
NewNotFoundError creates an error that occurs when the requested resource could not be found. Your client application tried to access a resource that does not exist (or could not be found). Please review how your users initiated such a request.
func NewServerError ¶
func NewServerError(errors ...ValidationError) *HTTPError
NewServerError creates an error that occurs when the server encounters an unexpected condition that prevents it from fulfilling the request. Your client application did everything correct. Unfortunately our API encountered a condition that resulted in this problem.
func NewServiceUnavailableError ¶
func NewServiceUnavailableError(errors ...ValidationError) *HTTPError
NewServiceUnavailableError creates an error that occurs when the service requested is currently unavailable and the server is not ready to handle the request. Your client application did everything correct. Unfortunately our API is currently unavailable.
func NewUnauthorizedError ¶
func NewUnauthorizedError(errors ...ValidationError) *HTTPError
NewUnauthorizedError creates an error that occurs when the request lacks valid authentication credentials. Your client application tried to access a resource without providing a valid access token or authentication information. Please ensure that your requests include the necessary authentication credentials.
func (HTTPError) IsBlankType ¶
IsBlankType checks if the type of error is empty or about:blank.
type ValidationError ¶
type ValidationError struct {
// A granular description on the specific error related to a body property, query parameter, path parameters, and/or header.
Detail string `json:"detail"`
// Name of the query, path, header, or cookie parameter that is the source of the error.
Parameter string `json:"parameter,omitempty"`
// A JSON Pointer to a specific property that is the source of the error.
Pointer string `json:"pointer,omitempty"`
// Location indicates where the error occurred (e.g., body, query, path, header, or cookie).
Location string `json:"location,omitempty"`
// A string containing additional provider specific codes to identify the error context.
Code string `json:"code,omitempty"`
// A hint text to guide how to fix the issue.
Hint string `json:"hint,omitempty"`
}
ValidationError is an object to provide explicit details on a problem towards an API consumer.
func (ValidationError) Error ¶
func (ed ValidationError) Error() string
Error implements the error interface for ValidationError.
func (*ValidationError) PrependPointer ¶
func (ed *ValidationError) PrependPointer(prefix string)
PrependPointer prepends the prefix to the pointer.