forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
errorcodes.go
52 lines (46 loc) · 1.61 KB
/
errorcodes.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
49
50
51
52
package errorpage
import "github.com/openshift/origin/pkg/auth/userregistry/identitymapper"
const (
// error occurred attempting to claim a user
errorCodeClaim = "mapping_claim_error"
// error occurred looking up the user
errorCodeLookup = "mapping_lookup_error"
// general authentication error
errorCodeAuthentication = "authentication_error"
// general grant error
errorCodeGrant = "grant_error"
)
// AuthenticationErrorCode returns an error code for the given authentication error.
// If the error is not recognized, a generic error code is returned.
func AuthenticationErrorCode(err error) string {
switch {
case identitymapper.IsClaimError(err):
return errorCodeClaim
case identitymapper.IsLookupError(err):
return errorCodeLookup
default:
return errorCodeAuthentication
}
}
// AuthenticationErrorMessage returns an error message for the given authentication error code.
// If the error code is not recognized, a generic error message is returned.
func AuthenticationErrorMessage(code string) string {
switch code {
case errorCodeClaim:
return "Could not create user."
case errorCodeLookup:
return "Could not find user."
default:
return "An authentication error occurred."
}
}
// GrantErrorCode returns an error code for the given grant error.
// If the error is not recognized, a generic error code is returned.
func GrantErrorCode(err error) string {
return errorCodeGrant
}
// GrantErrorMessage returns an error message for the given grant error code.
// If the error is not recognized, a generic error message is returned.
func GrantErrorMessage(code string) string {
return "A grant error occurred."
}