-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathrequest_errors.go
38 lines (30 loc) · 961 Bytes
/
request_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
package uaa
import (
"fmt"
"github.com/pkg/errors"
"golang.org/x/oauth2"
)
type RequestError struct {
Url string
ErrorResponse []byte
}
func (r RequestError) Error() string {
return fmt.Sprintf("An error occurred while calling %s %s", r.Url, string(r.ErrorResponse))
}
func requestErrorFromOauthError(err error) error {
oauthErrorResponse, isRetrieveError := err.(*oauth2.RetrieveError)
if isRetrieveError {
tokenUrl := oauthErrorResponse.Response.Request.URL.String()
return requestErrorWithBody(tokenUrl, oauthErrorResponse.Body)
}
return err
}
func requestErrorWithBody(url string, body []byte) error {
return RequestError{url, body}
}
func requestError(url string) error {
return errors.Errorf("An error occurred while calling %s", url)
}
func parseError(err error, url string, body []byte) error {
return errors.Wrapf(err, "An unknown error occurred while parsing response from %s. Response was %s", url, string(body))
}