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.") )
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" )
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.