forked from ktrysmt/go-bitbucket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
40 lines (32 loc) · 978 Bytes
/
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
package bitbucket
import (
"errors"
"fmt"
"github.com/mitchellh/mapstructure"
)
type BitbucketError struct {
Message string
Fields map[string][]string
}
func DecodeError(e map[string]interface{}) error {
var bitbucketError BitbucketError
err := mapstructure.Decode(e["error"], &bitbucketError)
if err != nil {
return err
}
return errors.New(bitbucketError.Message)
}
// UnexpectedResponseStatusError represents an unexpected status code
// returned from the API, along with the body, if it could be read. If the body
// could not be read, the body contains the error message trying to read it.
type UnexpectedResponseStatusError struct {
Status string
Body []byte
}
func (e *UnexpectedResponseStatusError) Error() string {
return e.Status
}
// ErrorWithBody returns an error with the given status and body.
func (e *UnexpectedResponseStatusError) ErrorWithBody() error {
return fmt.Errorf("unexpected status %s, body: %s", e.Status, string(e.Body))
}