refactor: add ErrorCodeToHttpStatus
This commit is contained in:
parent
3f90cbfe09
commit
1c3bfdc493
|
@ -1,6 +1,9 @@
|
||||||
package account
|
package account
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Account creation errors
|
// Account creation errors
|
||||||
|
@ -86,6 +89,50 @@ var defaultErrorMessages = map[string]string{
|
||||||
ErrKeyDatabaseOperationFailed: "A database operation failed.",
|
ErrKeyDatabaseOperationFailed: "A database operation failed.",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrorCodeToHttpStatus = map[string]int{
|
||||||
|
// Account creation errors
|
||||||
|
ErrKeyAccountCreationFailed: http.StatusInternalServerError,
|
||||||
|
ErrKeyEmailAlreadyExists: http.StatusConflict,
|
||||||
|
ErrKeyPasswordHashingFailed: http.StatusInternalServerError,
|
||||||
|
|
||||||
|
// Account lookup and existence verification errors
|
||||||
|
ErrKeyUserNotFound: http.StatusNotFound,
|
||||||
|
ErrKeyPublicKeyNotFound: http.StatusNotFound,
|
||||||
|
|
||||||
|
// Authentication and login errors
|
||||||
|
ErrKeyInvalidLogin: http.StatusUnauthorized,
|
||||||
|
ErrKeyInvalidPassword: http.StatusUnauthorized,
|
||||||
|
ErrKeyInvalidOTPCode: http.StatusBadRequest,
|
||||||
|
ErrKeyOTPVerificationFailed: http.StatusBadRequest,
|
||||||
|
ErrKeyLoginFailed: http.StatusInternalServerError,
|
||||||
|
|
||||||
|
// Account update errors
|
||||||
|
ErrKeyAccountUpdateFailed: http.StatusInternalServerError,
|
||||||
|
|
||||||
|
// JWT generation errors
|
||||||
|
ErrKeyJWTGenerationFailed: http.StatusInternalServerError,
|
||||||
|
|
||||||
|
// OTP management errors
|
||||||
|
ErrKeyOTPGenerationFailed: http.StatusInternalServerError,
|
||||||
|
ErrKeyOTPEnableFailed: http.StatusInternalServerError,
|
||||||
|
ErrKeyOTPDisableFailed: http.StatusInternalServerError,
|
||||||
|
|
||||||
|
// Public key management errors
|
||||||
|
ErrKeyAddPublicKeyFailed: http.StatusInternalServerError,
|
||||||
|
ErrKeyPublicKeyExists: http.StatusConflict,
|
||||||
|
|
||||||
|
// Pin management errors
|
||||||
|
ErrKeyPinAddFailed: http.StatusInternalServerError,
|
||||||
|
ErrKeyPinDeleteFailed: http.StatusInternalServerError,
|
||||||
|
ErrKeyPinsRetrievalFailed: http.StatusInternalServerError,
|
||||||
|
|
||||||
|
// General errors
|
||||||
|
ErrKeyDatabaseOperationFailed: http.StatusInternalServerError,
|
||||||
|
ErrKeyHashingFailed: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
type AccountError struct {
|
type AccountError struct {
|
||||||
Key string // A unique identifier for the error type
|
Key string // A unique identifier for the error type
|
||||||
Message string // Human-readable error message
|
Message string // Human-readable error message
|
||||||
|
|
Loading…
Reference in New Issue