MCPcopy Create free account
hub / github.com/AbelChe/evil_minio / toAPIError

Function toAPIError

cmd/api-errors.go:2300–2433  ·  view source on GitHub ↗

toAPIError - Converts embedded errors. Convenience function written to handle all cases where we have known types of errors returned by underlying layers.

(ctx context.Context, err error)

Source from the content-addressed store, hash-verified

2298// function written to handle all cases where we have known types of
2299// errors returned by underlying layers.
2300func toAPIError(ctx context.Context, err error) APIError {
2301 if err == nil {
2302 return noError
2303 }
2304
2305 apiErr := errorCodes.ToAPIErr(toAPIErrorCode(ctx, err))
2306 switch apiErr.Code {
2307 case "NotImplemented":
2308 desc := fmt.Sprintf("%s (%v)", apiErr.Description, err)
2309 apiErr = APIError{
2310 Code: apiErr.Code,
2311 Description: desc,
2312 HTTPStatusCode: apiErr.HTTPStatusCode,
2313 }
2314 case "XMinioBackendDown":
2315 apiErr.Description = fmt.Sprintf("%s (%v)", apiErr.Description, err)
2316 case "InternalError":
2317 // If we see an internal error try to interpret
2318 // any underlying errors if possible depending on
2319 // their internal error types.
2320 switch e := err.(type) {
2321 case kms.Error:
2322 apiErr = APIError{
2323 Description: e.Err.Error(),
2324 Code: e.APICode,
2325 HTTPStatusCode: e.HTTPStatusCode,
2326 }
2327 case batchReplicationJobError:
2328 apiErr = APIError(e)
2329 case InvalidArgument:
2330 apiErr = APIError{
2331 Code: "InvalidArgument",
2332 Description: e.Error(),
2333 HTTPStatusCode: errorCodes[ErrInvalidRequest].HTTPStatusCode,
2334 }
2335 case *xml.SyntaxError:
2336 apiErr = APIError{
2337 Code: "MalformedXML",
2338 Description: fmt.Sprintf("%s (%s)", errorCodes[ErrMalformedXML].Description, e),
2339 HTTPStatusCode: errorCodes[ErrMalformedXML].HTTPStatusCode,
2340 }
2341 case url.EscapeError:
2342 apiErr = APIError{
2343 Code: "XMinioInvalidObjectName",
2344 Description: fmt.Sprintf("%s (%s)", errorCodes[ErrInvalidObjectName].Description, e),
2345 HTTPStatusCode: http.StatusBadRequest,
2346 }
2347 case versioning.Error:
2348 apiErr = APIError{
2349 Code: "IllegalVersioningConfigurationException",
2350 Description: fmt.Sprintf("Versioning configuration specified in the request is invalid. (%s)", e),
2351 HTTPStatusCode: http.StatusBadRequest,
2352 }
2353 case lifecycle.Error:
2354 apiErr = APIError{
2355 Code: "InvalidRequest",
2356 Description: e.Error(),
2357 HTTPStatusCode: http.StatusBadRequest,

Calls 6

toAPIErrorCodeFunction · 0.85
APIErrorStruct · 0.85
ToAPIErrMethod · 0.80
ContainsMethod · 0.80
IsMethod · 0.80
ErrorMethod · 0.65

Tested by 3

TestIsReqAuthenticatedFunction · 0.68
TestToErrIsNilFunction · 0.68