-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy patherror.go
47 lines (38 loc) · 811 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
41
42
43
44
45
46
47
package s3
import (
"encoding/xml"
"fmt"
"io/ioutil"
"net/http"
)
type S3Error struct {
Code int
ShouldRetry bool
Body []byte
}
type S3NewEndpointError struct {
Code string
Message string
Bucket string
Endpoint string
}
func wrapError(resp *http.Response) *S3Error {
bodyBytes, _ := ioutil.ReadAll(resp.Body)
return &S3Error{
Code: resp.StatusCode,
ShouldRetry: resp.StatusCode == http.StatusInternalServerError,
Body: bodyBytes,
}
}
func (err *S3Error) Error() string {
return fmt.Sprintf("S3 Error: %d %s", err.Code, string(err.Body))
}
func (err *S3Error) newEndpoint() string {
msg := S3NewEndpointError{}
if er := xml.Unmarshal(err.Body, &msg); er == nil {
if msg.Code == "TemporaryRedirect" {
return msg.Endpoint
}
}
return ""
}