/
is.go
57 lines (50 loc) · 1.31 KB
/
is.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
53
54
55
56
57
package apperror
// IsNotFound checks if an error is the NotFound type
func IsNotFound(e error) bool {
err, casted := e.(*AppError)
if !casted {
return false
}
return err.StatusCode() == NotFound
}
// IsConflict checks if an error is caused by a conflict
func IsConflict(e error) bool {
err, casted := e.(*AppError)
if !casted {
return false
}
return err.StatusCode() == AlreadyExists
}
// IsInternalServerError checks if an error is caused by an internal error
func IsInternalServerError(e error) bool {
err := Convert(e)
return err.StatusCode() == Internal
}
// IsBadRequest checks if an error is caused by a bad request
func IsBadRequest(e error) bool {
err, casted := e.(*AppError)
if !casted {
return false
}
return err.StatusCode() == InvalidArgument
}
// IsForbidden checks if an error is caused by a forbidden access
func IsForbidden(e error) bool {
err, casted := e.(*AppError)
if !casted {
return false
}
return err.StatusCode() == PermissionDenied
}
// IsUnauthorized checks if an error is caused by an Unauthorized access
func IsUnauthorized(e error) bool {
err, casted := e.(*AppError)
if !casted {
return false
}
return err.StatusCode() == Unauthenticated
}
// IsInvalidParam checks if an error is caused by an invalid param
func IsInvalidParam(e error) bool {
return IsBadRequest(e)
}