s3_error_utils.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package s3api
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/glog"
  4. "github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
  5. )
  6. // ErrorHandlers provide common error handling patterns for S3 API operations
  7. // handlePutToFilerError logs an error and returns the standard putToFiler error format
  8. func handlePutToFilerError(operation string, err error, errorCode s3err.ErrorCode) (string, s3err.ErrorCode, string) {
  9. glog.Errorf("Failed to %s: %v", operation, err)
  10. return "", errorCode, ""
  11. }
  12. // handlePutToFilerInternalError is a convenience wrapper for internal errors in putToFiler
  13. func handlePutToFilerInternalError(operation string, err error) (string, s3err.ErrorCode, string) {
  14. return handlePutToFilerError(operation, err, s3err.ErrInternalError)
  15. }
  16. // handleMultipartError logs an error and returns the standard multipart error format
  17. func handleMultipartError(operation string, err error, errorCode s3err.ErrorCode) (interface{}, s3err.ErrorCode) {
  18. glog.Errorf("Failed to %s: %v", operation, err)
  19. return nil, errorCode
  20. }
  21. // handleMultipartInternalError is a convenience wrapper for internal errors in multipart operations
  22. func handleMultipartInternalError(operation string, err error) (interface{}, s3err.ErrorCode) {
  23. return handleMultipartError(operation, err, s3err.ErrInternalError)
  24. }
  25. // logErrorAndReturn logs an error with operation context and returns the specified error code
  26. func logErrorAndReturn(operation string, err error, errorCode s3err.ErrorCode) s3err.ErrorCode {
  27. glog.Errorf("Failed to %s: %v", operation, err)
  28. return errorCode
  29. }
  30. // logInternalError is a convenience wrapper for internal error logging
  31. func logInternalError(operation string, err error) s3err.ErrorCode {
  32. return logErrorAndReturn(operation, err, s3err.ErrInternalError)
  33. }
  34. // SSE-specific error handlers
  35. // handleSSEError handles common SSE-related errors with appropriate context
  36. func handleSSEError(sseType string, operation string, err error, errorCode s3err.ErrorCode) (string, s3err.ErrorCode, string) {
  37. glog.Errorf("Failed to %s for %s: %v", operation, sseType, err)
  38. return "", errorCode, ""
  39. }
  40. // handleSSEInternalError is a convenience wrapper for SSE internal errors
  41. func handleSSEInternalError(sseType string, operation string, err error) (string, s3err.ErrorCode, string) {
  42. return handleSSEError(sseType, operation, err, s3err.ErrInternalError)
  43. }