MCPcopy
hub / github.com/minio/minio-go / httpRespToErrorResponse

Function httpRespToErrorResponse

api-error-response.go:121–227  ·  view source on GitHub ↗

httpRespToErrorResponse returns a new encoded ErrorResponse structure as error.

(resp *http.Response, bucketName, objectName string)

Source from the content-addressed store, hash-verified

119// httpRespToErrorResponse returns a new encoded ErrorResponse
120// structure as error.
121func httpRespToErrorResponse(resp *http.Response, bucketName, objectName string) error {
122 if resp == nil {
123 msg := "Empty http response. " + reportIssue
124 return errInvalidArgument(msg)
125 }
126
127 errResp := ErrorResponse{
128 StatusCode: resp.StatusCode,
129 Server: resp.Header.Get("Server"),
130 }
131
132 success := successStatus.Contains(resp.StatusCode)
133
134 errBody, err := xmlDecodeAndBody(resp.Body, &errResp)
135 // Xml decoding failed with no body, fall back to HTTP headers.
136 if err != nil {
137 var unmarshalErr xml.UnmarshalError
138 if success && errors.As(err, &unmarshalErr) {
139 // This is a successful message so not an error response
140 // return nil,
141 return nil
142 }
143
144 switch resp.StatusCode {
145 case http.StatusNotFound:
146 if objectName == "" {
147 errResp = ErrorResponse{
148 StatusCode: resp.StatusCode,
149 Code: NoSuchBucket,
150 Message: s3ErrorResponseMap[NoSuchBucket],
151 BucketName: bucketName,
152 }
153 } else {
154 errResp = ErrorResponse{
155 StatusCode: resp.StatusCode,
156 Code: NoSuchKey,
157 Message: s3ErrorResponseMap[NoSuchKey],
158 BucketName: bucketName,
159 Key: objectName,
160 }
161 }
162 case http.StatusForbidden:
163 errResp = ErrorResponse{
164 StatusCode: resp.StatusCode,
165 Code: AccessDenied,
166 Message: s3ErrorResponseMap[AccessDenied],
167 BucketName: bucketName,
168 Key: objectName,
169 }
170 case http.StatusConflict:
171 errResp = ErrorResponse{
172 StatusCode: resp.StatusCode,
173 Code: Conflict,
174 Message: s3ErrorResponseMap[Conflict],
175 BucketName: bucketName,
176 }
177 case http.StatusPreconditionFailed:
178 errResp = ErrorResponse{

Callers 15

NewSelectResultsFunction · 0.85
GetObjectACLMethod · 0.85
BucketExistsMethod · 0.85
StatObjectMethod · 0.85
CreateSessionMethod · 0.85
appendObjectDoMethod · 0.85
PutObjectLegalHoldMethod · 0.85
GetObjectLegalHoldMethod · 0.85
executeMethodMethod · 0.85
doMakeBucketMethod · 0.85
RemoveBucketMethod · 0.85

Calls 4

errInvalidArgumentFunction · 0.85
xmlDecodeAndBodyFunction · 0.70
GetMethod · 0.45
ContainsMethod · 0.45

Tested by 2

TestErrorResponseFunction · 0.68