-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.go
More file actions
71 lines (58 loc) · 1.85 KB
/
errors.go
File metadata and controls
71 lines (58 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package limen
import (
"errors"
"net/http"
)
type LimenError struct {
message string
details any
status int
}
var (
ErrDatabaseAdapterRequired = errors.New("database adapter is required")
ErrPluginNotFound = errors.New("plugin not found")
ErrPluginAlreadyRegistered = errors.New("plugin already registered")
ErrInvalidConfiguration = errors.New("invalid configuration")
ErrRecordNotFound = NewLimenError("record not found", http.StatusNotFound, nil)
ErrEmptyText = errors.New("text is empty and cannot be encrypted or decrypted")
ErrMissingConditions = errors.New("missing query conditions")
)
// Session-specific errors
var (
ErrSessionNotFound = errors.New("session not found")
ErrSessionExpired = errors.New("session has expired")
ErrSessionInvalid = errors.New("session is invalid")
)
// Rate limiting errors
var (
ErrRateLimitExceeded = errors.New("rate limit exceeded")
ErrRateLimitNotFound = errors.New("rate limit not found")
)
// Verification errors
var (
ErrVerificationTokenInvalid = errors.New("verification token is invalid")
)
// Email verification errors
var (
ErrEmailAlreadyVerified = NewLimenError("email already verified", http.StatusConflict, nil)
ErrEmailVerificationTokenInvalid = NewLimenError("invalid or expired email verification token", http.StatusBadRequest, nil)
)
func NewLimenError(message string, status int, details any) *LimenError {
return &LimenError{message: message, details: details, status: status}
}
func (e *LimenError) Error() string {
return e.message
}
func (e *LimenError) Details() any {
return e.details
}
func (e *LimenError) Status() int {
return e.status
}
func ToLimenError(err error) *LimenError {
var limenErr *LimenError
if errors.As(err, &limenErr) {
return limenErr
}
return NewLimenError(err.Error(), http.StatusInternalServerError, err)
}