-
Notifications
You must be signed in to change notification settings - Fork 24
/
errors.go
55 lines (44 loc) · 1.05 KB
/
errors.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
package common
import (
"errors"
"net/http"
"net/url"
"strings"
"github.com/cloudfoundry-incubator/notifications/uaa"
)
type UAAUserNotFoundError struct {
Err error
}
func (e UAAUserNotFoundError) Error() string {
return e.Err.Error()
}
type UAADownError struct {
Err error
}
func (e UAADownError) Error() string {
return e.Err.Error()
}
type UAAGenericError struct {
Err error
}
func (e UAAGenericError) Error() string {
return e.Err.Error()
}
func UAAErrorFor(err error) error {
switch err.(type) {
case *url.Error:
return UAADownError{errors.New("UAA is unavailable")}
case uaa.Failure:
failure := err.(uaa.Failure)
if failure.Code() == http.StatusNotFound {
if strings.Contains(failure.Message(), "Requested route") {
return UAADownError{errors.New("UAA is unavailable")}
} else {
return UAAGenericError{errors.New("UAA Unknown 404 error message: " + failure.Message())}
}
}
return UAADownError{errors.New(failure.Message())}
default:
return UAAGenericError{errors.New("UAA Unknown Error: " + err.Error())}
}
}