Documentation
¶
Overview ¶
Package apierr defines the stable, machine-readable error contract of Auth-All. Error codes are part of the public API compatibility surface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidRequest = New(CodeInvalidRequest, http.StatusBadRequest, "The request is invalid.") ErrInvalidCredentials = New(CodeInvalidCredentials, http.StatusUnauthorized, "Invalid email or password.") ErrEmailAlreadyExists = New(CodeEmailAlreadyExists, http.StatusConflict, "An account with this email already exists.") ErrWeakPassword = New(CodeWeakPassword, http.StatusBadRequest, "The password does not meet the password policy.") ErrInvalidToken = New(CodeInvalidToken, http.StatusBadRequest, "The token is invalid or expired.") ErrForbidden = New(CodeForbidden, http.StatusForbidden, "The operation is not permitted.") ErrNotFound = New(CodeNotFound, http.StatusNotFound, "The resource does not exist.") ErrMethodNotAllowed = New(CodeMethodNotAllowed, http.StatusMethodNotAllowed, "The method is not allowed.") ErrOriginNotAllowed = New(CodeOriginNotAllowed, http.StatusForbidden, "The request origin is not allowed.") ErrEmailNotVerified = New(CodeEmailNotVerified, http.StatusForbidden, "The email address is not verified.") ErrNoPasswordCredential = New(CodeNoPasswordCredential, http.StatusBadRequest, "This account has no password.") ErrAccountAlreadyLinked = New(CodeAccountAlreadyLinked, http.StatusConflict, "This provider account is already linked to another user.") ErrAccountNotLinked = New(CodeAccountNotLinked, http.StatusNotFound, "This provider account is not linked.") ErrLastAuthMethod = New(CodeLastAuthMethod, http.StatusConflict, "The last remaining authentication method cannot be removed.") ErrProviderNotFound = New(CodeProviderNotFound, http.StatusNotFound, "The provider is not configured.") ErrOAuthStateInvalid = New(CodeOAuthStateInvalid, http.StatusBadRequest, "The OAuth state is invalid or expired.") ErrOAuthFailed = New(CodeOAuthFailed, http.StatusBadRequest, "The provider did not complete authentication.") ErrRateLimited = New(CodeRateLimited, http.StatusTooManyRequests, "Too many requests.") // ErrInvalidTOTPCode reports a code that does not authenticate. The message // names no reason, so a wrong code and a replayed code look equal. ErrInvalidTOTPCode = New(CodeInvalidTOTPCode, http.StatusBadRequest, "The code is invalid.") ErrTOTPNotEnrolled = New(CodeTOTPNotEnrolled, http.StatusBadRequest, "No second factor is set up.") ErrTOTPAlreadyEnrolled = New(CodeTOTPAlreadyEnrolled, http.StatusConflict, "A second factor is already set up.") // ErrInvalidRecoveryCode reports a recovery code that does not match. The // message names no reason, so a wrong code and a spent code look equal. ErrInvalidRecoveryCode = New(CodeInvalidRecoveryCode, http.StatusBadRequest, "The recovery code is invalid.") ErrInternal = New(CodeInternal, http.StatusInternalServerError, "An internal error occurred.") // Errors of the v0.3.0 release. ErrInsufficientRole = New(CodeInsufficientRole, http.StatusForbidden, "The role of the caller is too low.") ErrRoleUnknown = New(CodeRoleUnknown, http.StatusBadRequest, "The role is not configured.") ErrRoleNotAllowed = New(CodeRoleNotAllowed, http.StatusForbidden, "The role is above the role of the caller.") // ErrUserDisabled appears only after a correct password, so it tells // nothing to a caller without the password. ErrUserDisabled = New(CodeUserDisabled, http.StatusForbidden, "The account is disabled.") ErrPasswordChangeRequired = New(CodePasswordChangeRequired, http.StatusForbidden, "The password must change before this operation.") ErrLastAdmin = New(CodeLastAdmin, http.StatusConflict, "The last enabled administrator cannot lose the role.") ErrAPIKeyExpiryTooLong = New(CodeAPIKeyExpiryTooLong, http.StatusBadRequest, "The expiry is above the maximum.") ErrAPIKeyExpiryRequired = New(CodeAPIKeyExpiryRequired, http.StatusBadRequest, "An expiry is required.") // Errors of the v0.4.0 release. ErrSlugTaken = New(CodeSlugTaken, http.StatusConflict, "The slug belongs to another organization.") ErrPermissionDenied = New(CodePermissionDenied, http.StatusForbidden, "The permission set does not hold the statement.") ErrNoActiveOrganization = New(CodeNoActiveOrganization, http.StatusForbidden, "The session names no organization.") ErrNotAMember = New(CodeNotAMember, http.StatusForbidden, "The user holds no active membership.") ErrAlreadyMember = New(CodeAlreadyMember, http.StatusConflict, "The address already holds a membership.") ErrLastOwner = New(CodeLastOwner, http.StatusConflict, "The last owner cannot lose the role.") // ErrInvitationInvalid names no reason, so an unknown invitation, a used // invitation, a revoked invitation, and an expired invitation look equal. ErrInvitationInvalid = New(CodeInvitationInvalid, http.StatusBadRequest, "The invitation is invalid.") ErrMemberLimit = New(CodeMemberLimit, http.StatusConflict, "The organization reached its member limit.") )
Predefined errors.
Functions ¶
func Write ¶
func Write(w http.ResponseWriter, err error)
Write serializes err as the public error envelope.
Types ¶
type Body ¶
type Body struct {
Error Payload `json:"error"`
}
Body is the serialized public error envelope.
type Code ¶
type Code string
Code is a stable machine-readable error code.
const ( CodeInvalidRequest Code = "INVALID_REQUEST" CodeInvalidCredentials Code = "INVALID_CREDENTIALS" CodeEmailAlreadyExists Code = "EMAIL_ALREADY_EXISTS" CodeWeakPassword Code = "WEAK_PASSWORD" CodeInvalidToken Code = "INVALID_TOKEN" CodeForbidden Code = "FORBIDDEN" CodeNotFound Code = "NOT_FOUND" CodeMethodNotAllowed Code = "METHOD_NOT_ALLOWED" CodeOriginNotAllowed Code = "ORIGIN_NOT_ALLOWED" CodeEmailNotVerified Code = "EMAIL_NOT_VERIFIED" CodeNoPasswordCredential Code = "NO_PASSWORD_CREDENTIAL" CodeAccountAlreadyLinked Code = "ACCOUNT_ALREADY_LINKED" CodeAccountNotLinked Code = "ACCOUNT_NOT_LINKED" CodeLastAuthMethod Code = "LAST_AUTH_METHOD" CodeProviderNotFound Code = "PROVIDER_NOT_FOUND" CodeOAuthStateInvalid Code = "OAUTH_STATE_INVALID" CodeOAuthFailed Code = "OAUTH_FAILED" CodeRateLimited Code = "RATE_LIMITED" CodeInvalidTOTPCode Code = "INVALID_TOTP_CODE" CodeTOTPNotEnrolled Code = "TOTP_NOT_ENROLLED" CodeTOTPAlreadyEnrolled Code = "TOTP_ALREADY_ENROLLED" CodeInvalidRecoveryCode Code = "INVALID_RECOVERY_CODE" CodeInternal Code = "INTERNAL" // Codes of the v0.3.0 release. A released code never changes its meaning. CodeInsufficientRole Code = "INSUFFICIENT_ROLE" CodeRoleUnknown Code = "ROLE_UNKNOWN" CodeRoleNotAllowed Code = "ROLE_NOT_ALLOWED" CodeUserDisabled Code = "USER_DISABLED" CodePasswordChangeRequired Code = "PASSWORD_CHANGE_REQUIRED" CodeLastAdmin Code = "LAST_ADMIN" CodeAPIKeyExpiryTooLong Code = "API_KEY_EXPIRY_TOO_LONG" CodeAPIKeyExpiryRequired Code = "API_KEY_EXPIRY_REQUIRED" // Codes of the v0.4.0 release. A released code never changes its meaning. CodeSlugTaken Code = "SLUG_TAKEN" CodePermissionDenied Code = "PERMISSION_DENIED" CodeNoActiveOrganization Code = "NO_ACTIVE_ORGANIZATION" CodeNotAMember Code = "NOT_A_MEMBER" CodeAlreadyMember Code = "ALREADY_MEMBER" CodeLastOwner Code = "LAST_OWNER" CodeInvitationInvalid Code = "INVITATION_INVALID" CodeMemberLimit Code = "MEMBER_LIMIT" )
Stable public error codes.
type Error ¶
Error is a public Auth-All error. It carries a stable code, a safe public message, and an optional private cause. The cause is never serialized.
func From ¶
From maps any error to a public error. Unknown errors map to INTERNAL so that internal details never reach a client.
func (*Error) WithMessage ¶
WithMessage returns a copy with a different public message.
Click to show internal directories.
Click to hide internal directories.