-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.go
48 lines (40 loc) · 1.51 KB
/
error.go
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
package user
import (
"errors"
"fmt"
"net/http"
)
type authErr struct {
code int
err error
}
// Code returns the HTTP status code for the error
func (e authErr) Code() int {
return e.code
}
// Err returns the wrapped error
func (e authErr) Err() error {
return e.err
}
func (e authErr) Unwrap() error {
return e.err
}
// Error returns the error string
func (e authErr) Error() string {
return fmt.Sprintf("[%d] %s", e.code, e.err.Error())
}
// AuthErr is the interface to get more info on an auth error
type AuthErr interface {
error
Code() int
Err() error
}
var errJWTMalformed = authErr{code: http.StatusUnauthorized, err: errors.New("malformed JWT")}
var errJWTTime = authErr{code: http.StatusUnauthorized, err: errors.New("JWT expired or not yet valid")}
var errJWTSignature = authErr{code: http.StatusUnauthorized, err: errors.New("invalid JWT signature")}
var errJWTInvalid = authErr{code: http.StatusUnauthorized, err: errors.New("invalid JWT")}
var errLoginMissingAuth = authErr{code: http.StatusUnauthorized, err: errors.New("no authorization header")}
var errLoginInvalidAuth = authErr{code: http.StatusBadRequest, err: errors.New("invalid authorization header")}
var errLoginAuthNotFound = authErr{code: http.StatusBadRequest, err: errors.New("invalid authorization header")}
var errLoginInvalidUserPass = authErr{code: http.StatusBadRequest, err: errors.New("invalid username or password")}
var errLoginIncorrectUserPass = authErr{code: http.StatusUnauthorized, err: errors.New("incorrect username or password")}