forked from Azure/azure-storage-azcopy
/
ErrorExt.go
43 lines (37 loc) · 1.24 KB
/
ErrorExt.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
package ste
import (
"net/http"
"github.com/nitin-deamon/azure-storage-azcopy/v10/azbfs"
"github.com/Azure/azure-storage-blob-go/azblob"
"github.com/Azure/azure-storage-file-go/azfile"
)
type ErrorEx struct {
error
}
// TODO: consider rolling MSRequestID into this, so that all places that use this can pick up, and log, the request ID too
func (errex ErrorEx) ErrorCodeAndString() (string, int, string) {
switch e := interface{}(errex.error).(type) {
case azblob.StorageError:
return string(e.ServiceCode()), e.Response().StatusCode, e.Response().Status
case azfile.StorageError:
return string(e.ServiceCode()), e.Response().StatusCode, e.Response().Status
case azbfs.StorageError:
return string(e.ServiceCode()), e.Response().StatusCode, e.Response().Status
default:
return "", 0, errex.Error()
}
}
type hasResponse interface {
Response() *http.Response
}
// MSRequestID gets the request ID guid associated with the failed request.
// Returns "" if there isn't one (either no request, or there is a request but it doesn't have the header)
func (errex ErrorEx) MSRequestID() string {
if respErr, ok := errex.error.(hasResponse); ok {
r := respErr.Response()
if r != nil {
return r.Header.Get("X-Ms-Request-Id")
}
}
return ""
}