Documentation
¶
Index ¶
- func HttpErrorHandle(err error, response *http.Response) error
- type ErrorCode
- type ErrorMessage
- type ErrorType
- type PermitError
- func NewPermitConflictError(response *http.Response) PermitError
- func NewPermitConnectionError(err error) PermitError
- func NewPermitContextError(additionalMessage ErrorMessage) PermitError
- func NewPermitContextErrorWithCause(additionalMessage ErrorMessage, cause error) PermitError
- func NewPermitDuplicateEntityError(err error, response *http.Response) PermitError
- func NewPermitError(errorMessage ErrorMessage, errorCode ErrorCode, errorType ErrorType, ...) PermitError
- func NewPermitForbiddenError(response *http.Response) PermitError
- func NewPermitNotFoundError(err error, response *http.Response) PermitError
- func NewPermitPaginationError() PermitError
- func NewPermitUnauthorizedError(response *http.Response) PermitError
- func NewPermitUnexpectedError(err error, response *http.Response) PermitError
- func NewPermitUnprocessableEntityError(err error, response *http.Response) PermitError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HttpErrorHandle ¶
HttpErrorHandle converts err and response into a PermitError. With a nil response it returns err unchanged. Statuses 401, 403, 404, 409 and 422 map to their own error codes, and any other status outside 200-299 maps to UnexpectedError, also when err is nil. For a status in 200-299 it returns nil when err is nil, and UnexpectedError otherwise.
Types ¶
type ErrorCode ¶
type ErrorCode string
const ( UnexpectedError ErrorCode = "UnexpectedError" NotFound ErrorCode = "NotFound" Conflict ErrorCode = "Conflict" PaginationError ErrorCode = "PaginationError" TeapotError ErrorCode = "TeapotError" ContextError ErrorCode = "ContextError" DuplicateEntity ErrorCode = "DuplicateEntity" ConnectionError ErrorCode = "ConnectionError" UnprocessableEntityError ErrorCode = "UnprocessableEntityError" EmptyDecisionLogs ErrorCode = "EmptyDecisionLogs" MissingRequestAttribute ErrorCode = "MissingRequestAttribute" ForbiddenAccess ErrorCode = "ForbiddenAccess" InvalidPermissionFormat ErrorCode = "InvalidPermissionFormat" MissingPermissions ErrorCode = "MissingPermissions" UnsupportedAttributeType ErrorCode = "UnsupportedAttributeType" MissingResourceAttribute ErrorCode = "MissingResourceAttribute" InvalidPolicyRepoStatus ErrorCode = "InvalidPolicyRepoStatus" MismatchAttributesTypes ErrorCode = "MismatchAttributesTypes" )
type ErrorMessage ¶
type ErrorMessage string
const ( EmptyErrorMessage ErrorMessage = "" PaginationMessage ErrorMessage = "The pagination page and size per page are invalid" ConflictMessage ErrorMessage = "The resource already exists" NotFoundMessage ErrorMessage = "The resource was not found" UnexpectedErrorMessage ErrorMessage = "An unexpected error happened." ForbiddenMessage ErrorMessage = "The access for this object is forbidden using the provided API key" ContextMessage ErrorMessage = "The context is missing or invalid" ContextUnexpectedMessage ErrorMessage = "The context is missing or invalid" DuplicateEntityMessage ErrorMessage = "The entity already exists" ConnectionErrorMessage ErrorMessage = "The connection to the api failed" UnprocessableEntityMessage ErrorMessage = "The entity send with the request is not valid" )
type PermitError ¶
type PermitError struct {
StatusCode int
ResponseBody string
ErrorCode ErrorCode
ErrorType ErrorType
// contains filtered or unexported fields
}
func NewPermitConflictError ¶
func NewPermitConflictError(response *http.Response) PermitError
func NewPermitConnectionError ¶
func NewPermitConnectionError(err error) PermitError
func NewPermitContextError ¶
func NewPermitContextError(additionalMessage ErrorMessage) PermitError
func NewPermitContextErrorWithCause ¶ added in v1.3.0
func NewPermitContextErrorWithCause(additionalMessage ErrorMessage, cause error) PermitError
NewPermitContextErrorWithCause returns a ContextError that wraps cause, so errors.Is, errors.As and errors.Unwrap reach it, and whose text ends with the text of cause. When cause is a PermitError with a status code, the text also gives that status, and StatusCode and ResponseBody are copied from cause.
func NewPermitDuplicateEntityError ¶
func NewPermitDuplicateEntityError(err error, response *http.Response) PermitError
func NewPermitError ¶
func NewPermitError(errorMessage ErrorMessage, errorCode ErrorCode, errorType ErrorType, response *http.Response) PermitError
NewPermitError returns a PermitError whose text and ResponseBody have the API key that the request was sent with and the values that start with permit_key_ replaced by [REDACTED]. In a JSON ResponseBody, the values under keys that name a credential, such as secret, token, api_key, password and authorization, are replaced too. The API key is taken from the Authorization header of response.Request, and is replaced only when it has at least 16 characters; with a transport that does not set Response.Request, the other values are still replaced.
func NewPermitForbiddenError ¶
func NewPermitForbiddenError(response *http.Response) PermitError
func NewPermitNotFoundError ¶
func NewPermitNotFoundError(err error, response *http.Response) PermitError
func NewPermitPaginationError ¶
func NewPermitPaginationError() PermitError
func NewPermitUnauthorizedError ¶
func NewPermitUnauthorizedError(response *http.Response) PermitError
func NewPermitUnexpectedError ¶
func NewPermitUnexpectedError(err error, response *http.Response) PermitError
func NewPermitUnprocessableEntityError ¶
func NewPermitUnprocessableEntityError(err error, response *http.Response) PermitError
func (PermitError) Unwrap ¶ added in v1.3.0
func (p PermitError) Unwrap() error
Unwrap returns the error that caused p, or nil when p records no cause.