Documentation
¶
Index ¶
- Constants
- func GenericErrorEncoder() encoder.ErrorEncoder
- func MakeSentenceCase(msg string) string
- func NewV3ErrorHandlerFunc(logger errorsx.Handler) func(w http.ResponseWriter, r *http.Request, err error)
- type BaseAPIError
- func NewBadRequestError(ctx context.Context, err error, invalidFields InvalidParameters) *BaseAPIError
- func NewConflictError(ctx context.Context, err error, detail string) *BaseAPIError
- func NewEmptySetResponse(ctx context.Context, cursorPagination bool) *BaseAPIError
- func NewForbiddenError(ctx context.Context, err error) *BaseAPIError
- func NewForbiddenErrorDetail(ctx context.Context, detailMessage string) *BaseAPIError
- func NewGoneError(ctx context.Context, err error) *BaseAPIError
- func NewInternalError(ctx context.Context, err error) *BaseAPIError
- func NewMethodNotAllowedError(ctx context.Context) *BaseAPIError
- func NewNotFoundError(ctx context.Context, err error, entityType string) *BaseAPIError
- func NewNotFoundErrors(ctx context.Context, err error, entityType string, resources any) *BaseAPIError
- func NewNotImplementedError(ctx context.Context, err error) *BaseAPIError
- func NewPreconditionFailedError(ctx context.Context, precondition string) *BaseAPIError
- func NewRateLimitError(ctx context.Context) *BaseAPIError
- func NewServiceUnavailable(ctx context.Context, err error) *BaseAPIError
- func NewUnauthenticatedError(ctx context.Context, err error) *BaseAPIError
- type InvalidParameter
- type InvalidParameterSource
- type InvalidParameters
Constants ¶
const ( // Content Type ContentTypeKey = "Content-Type" ContentTypeProblemValue = "application/problem+json" // Internal InternalType = "https://kongapi.info/konnect/internal" InternalTitle = "Internal" InternalDetail = "An internal failure occurred" // Service Unavailable // NotImplemented NotImplementedType = "https://kongapi.info/konnect/not-implemented" NotImplementedTitle = "Not Implemented" NotImplementedDetail = "The requested functionality is not implemented" // Unauthenticated UnauthenticatedType = "https://kongapi.info/konnect/unauthenticated" UnauthenticatedTitle = "Unauthenticated" UnauthenticatedDetail = "A valid token is required" // Forbidden ForbiddenType = "https://kongapi.info/konnect/unauthorized" ForbiddenTitle = "Forbidden" ForbiddenDetail = "Permission denied" // NotFound NotFoundType = "https://kongapi.info/konnect/not-found" NotFoundTitle = "Not Found" NotFoundDetail = "The requested %s was not found" NotFoundDetails = "The requested %s were not found: %v" // Method Not Allowed MethodNotAllowedType = "https://kongapi.info/konnect/method-not-allowed" MethodNotAllowedTitle = "Method Not Allowed" MethodNotAllowedDetail = "The requested method is not allowed" // BadRequest BadRequestType = "https://kongapi.info/konnect/bad-request" BadRequestTitle = "Bad Request" // Gone GoneType = "https://kongapi.info/konnect/gone" GoneTitle = "Gone" GoneDetail = "The requested resource is no longer available" // Precondition Failed PreconditionFailedType = "https://kongapi.info/konnect/precondition-failed" PreconditionFailedTitle = "Precondition Failed" // Rate Limit RateLimitType = "https://kongapi.info/konnect/rate-limited" RateLimitTitle = "Rate Limited" RateLimitDetail = "Too many requests" // Conflict ConflictType = "https://kongapi.info/konnect/resource-conflict" ConflictTitle = "Conflict" // Empty Set EmptySetType = "Empty Set" EmptySetCursorType = "Empty Set Cursor" )
Variables ¶
This section is empty.
Functions ¶
func GenericErrorEncoder ¶
func GenericErrorEncoder() encoder.ErrorEncoder
GenericErrorEncoder is an error encoder that encodes the error as a generic error.
func MakeSentenceCase ¶
MakeSentenceCase takes any string and returns a Sentence case version of it
func NewV3ErrorHandlerFunc ¶
func NewV3ErrorHandlerFunc(logger errorsx.Handler) func(w http.ResponseWriter, r *http.Request, err error)
NewV3ErrorHandlerFunc returns an oapi-codegen ChiServerOptions.ErrorHandlerFunc implementation.
It is invoked when the generated router fails request binding (query/path/header parsing). The main purpose is to ensure we always write a response (otherwise net/http defaults to 200 with an empty body), and to keep error-to-status mapping consistent with our model error types.
Types ¶
type BaseAPIError ¶
type BaseAPIError struct {
// A unique identifier for this error. When dereferenced it must provide
// human-readable documentation for the problem. The URL must follow
// (#122 - Resource Names) and must not contain URI fragments type.
Type string `json:"type"`
// The HTTP status code of the error. Useful when passing the response body
// to child properties in a frontend UI. Must be returned as an integer.
Status int `json:"status"`
// A short, human-readable summary of the problem. It should not change
// between occurrences of a problem, except for localization. Should be
// provided as "Sentence case" for direct use in the UI.
Title string `json:"title"`
// Used to return the correlation ID back to the user, in the format
// {product}:trace:<trace_id>. This helps us find the relevant logs when a
// customer reports an issue.
Instance string `json:"instance"`
// A human-readable explanation specific to this occurrence of the problem.
// This field may contain request/entity data to help the user understand
// what went wrong. Enclose variable values in square brackets. Should be
// provided as "Sentence case" for direct use in the UI.
Detail string `json:"detail"`
// Used to indicate which fields have invalid values when validated. Both a
// human-readable value (reason) and a type that can be used for localized
// results (rule) are provided.
InvalidParameters InvalidParameters `json:"invalid_parameters,omitempty"`
// UnderlyingError is the underlying error stack to be logged.
// NOTE: this should not be returned to callers.
UnderlyingError error `json:"-"`
// contains filtered or unexported fields
}
BaseAPIError is the schema for all API apierrors.
func NewBadRequestError ¶
func NewBadRequestError(ctx context.Context, err error, invalidFields InvalidParameters) *BaseAPIError
NewBadRequestError generates a bad request error.
func NewConflictError ¶
func NewConflictError(ctx context.Context, err error, detail string) *BaseAPIError
func NewEmptySetResponse ¶
func NewEmptySetResponse(ctx context.Context, cursorPagination bool) *BaseAPIError
func NewForbiddenError ¶
func NewForbiddenError(ctx context.Context, err error) *BaseAPIError
NewForbiddenError generates an unauthorized error.
func NewForbiddenErrorDetail ¶
func NewForbiddenErrorDetail(ctx context.Context, detailMessage string) *BaseAPIError
NewForbiddenErrorDetail generates an forbidden error with a user readable/detailed message.
func NewGoneError ¶
func NewGoneError(ctx context.Context, err error) *BaseAPIError
NewGoneError generates a gone error.
func NewInternalError ¶
func NewInternalError(ctx context.Context, err error) *BaseAPIError
NewInternalError generates an internal server error.
func NewMethodNotAllowedError ¶
func NewMethodNotAllowedError(ctx context.Context) *BaseAPIError
NewMethodNotAllowedError generates a method not allowed error.
func NewNotFoundError ¶
func NewNotFoundError(ctx context.Context, err error, entityType string) *BaseAPIError
NewNotFoundError generates a not found error.
func NewNotFoundErrors ¶
func NewNotFoundErrors( ctx context.Context, err error, entityType string, resources any, ) *BaseAPIError
NewNotFoundErrors generates a not found error for multiple resources.
func NewNotImplementedError ¶
func NewNotImplementedError(ctx context.Context, err error) *BaseAPIError
func NewPreconditionFailedError ¶
func NewPreconditionFailedError(ctx context.Context, precondition string) *BaseAPIError
NewPreconditionFailedError generates an precondition failed error.
func NewRateLimitError ¶
func NewRateLimitError(ctx context.Context) *BaseAPIError
NewRateLimitError generates an HTTP 429 Too Many Requests error.
func NewServiceUnavailable ¶
func NewServiceUnavailable(ctx context.Context, err error) *BaseAPIError
NewServiceUnavailable generates a not found error.
func NewUnauthenticatedError ¶
func NewUnauthenticatedError(ctx context.Context, err error) *BaseAPIError
NewUnauthenticatedError generates an unauthenticated error.
func (*BaseAPIError) Context ¶
func (bae *BaseAPIError) Context() context.Context
Context is the context that created the error
func (*BaseAPIError) Error ¶
func (bae *BaseAPIError) Error() string
Error satisfies the error interface.
func (*BaseAPIError) HandleAPIError ¶
func (bae *BaseAPIError) HandleAPIError( w http.ResponseWriter, r *http.Request, )
HandleAPIError is a helper function that accepts an error
func (*BaseAPIError) Unwrap ¶
func (bae *BaseAPIError) Unwrap() error
Unwrap returns the underlying error
type InvalidParameter ¶
type InvalidParameter struct {
// Field concerned by the error.
Field string `json:"field"`
// Rule represents the rule that has triggered the error.
Rule string `json:"rule,omitempty"`
// Reason describes why the error has been triggered.
Reason string `json:"reason"`
// Source describes where the error has been triggered: body, header, path.
Source InvalidParameterSource `json:"source"`
// Choices represents the available choices for value in a case of an enum.
Choices []string `json:"choices,omitempty"`
// Minimum is an optional field for setting the minimum required value for
// an attribute.
Minimum *int `json:"minimum,omitempty"`
// Maximum is an optional field for setting the maximum required value for
// an attribute.
Maximum *int `json:"maximum,omitempty"`
// Dependents is an optional field for when the rule "dependent_fields" is
// applied.
Dependents []string `json:"dependents,omitempty"`
}
InvalidParameter is a single field that failed input validation.
type InvalidParameterSource ¶
type InvalidParameterSource uint8
const ( InvalidParamSourcePath InvalidParameterSource = iota + 1 InvalidParamSourceQuery InvalidParamSourceBody InvalidParamSourceHeader )
func ToInvalid ¶
func ToInvalid(s string) InvalidParameterSource
func (InvalidParameterSource) MarshalJSON ¶
func (i InvalidParameterSource) MarshalJSON() ([]byte, error)
func (InvalidParameterSource) String ¶
func (i InvalidParameterSource) String() string
func (*InvalidParameterSource) UnmarshalJSON ¶
func (i *InvalidParameterSource) UnmarshalJSON(data []byte) error
type InvalidParameters ¶
type InvalidParameters []InvalidParameter
InvalidParameters is a collection of fields that failed input validation.
func (InvalidParameters) String ¶
func (ips InvalidParameters) String() string
Stringer method for a collection of InvalidParameter entities.