diff options
| author | chrislu <chris.lu@gmail.com> | 2025-08-30 11:18:03 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2025-08-30 11:18:03 -0700 |
| commit | 87021a146027f83f911619f71b9c27bd51e9d55a (patch) | |
| tree | c7720f1c285683ce19d28931bd7c11b5475a2844 /weed/s3api/s3_error_utils.go | |
| parent | 0748214c8e2f497a84b9392d2d7d4ec976bc84eb (diff) | |
| parent | 879d512b552d834136cfb746a239e6168e5c4ffb (diff) | |
| download | seaweedfs-origin/add-ec-vacuum.tar.xz seaweedfs-origin/add-ec-vacuum.zip | |
Merge branch 'master' into add-ec-vacuumorigin/add-ec-vacuum
Diffstat (limited to 'weed/s3api/s3_error_utils.go')
| -rw-r--r-- | weed/s3api/s3_error_utils.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/weed/s3api/s3_error_utils.go b/weed/s3api/s3_error_utils.go new file mode 100644 index 000000000..7afb241b5 --- /dev/null +++ b/weed/s3api/s3_error_utils.go @@ -0,0 +1,54 @@ +package s3api + +import ( + "github.com/seaweedfs/seaweedfs/weed/glog" + "github.com/seaweedfs/seaweedfs/weed/s3api/s3err" +) + +// ErrorHandlers provide common error handling patterns for S3 API operations + +// handlePutToFilerError logs an error and returns the standard putToFiler error format +func handlePutToFilerError(operation string, err error, errorCode s3err.ErrorCode) (string, s3err.ErrorCode, string) { + glog.Errorf("Failed to %s: %v", operation, err) + return "", errorCode, "" +} + +// handlePutToFilerInternalError is a convenience wrapper for internal errors in putToFiler +func handlePutToFilerInternalError(operation string, err error) (string, s3err.ErrorCode, string) { + return handlePutToFilerError(operation, err, s3err.ErrInternalError) +} + +// handleMultipartError logs an error and returns the standard multipart error format +func handleMultipartError(operation string, err error, errorCode s3err.ErrorCode) (interface{}, s3err.ErrorCode) { + glog.Errorf("Failed to %s: %v", operation, err) + return nil, errorCode +} + +// handleMultipartInternalError is a convenience wrapper for internal errors in multipart operations +func handleMultipartInternalError(operation string, err error) (interface{}, s3err.ErrorCode) { + return handleMultipartError(operation, err, s3err.ErrInternalError) +} + +// logErrorAndReturn logs an error with operation context and returns the specified error code +func logErrorAndReturn(operation string, err error, errorCode s3err.ErrorCode) s3err.ErrorCode { + glog.Errorf("Failed to %s: %v", operation, err) + return errorCode +} + +// logInternalError is a convenience wrapper for internal error logging +func logInternalError(operation string, err error) s3err.ErrorCode { + return logErrorAndReturn(operation, err, s3err.ErrInternalError) +} + +// SSE-specific error handlers + +// handleSSEError handles common SSE-related errors with appropriate context +func handleSSEError(sseType string, operation string, err error, errorCode s3err.ErrorCode) (string, s3err.ErrorCode, string) { + glog.Errorf("Failed to %s for %s: %v", operation, sseType, err) + return "", errorCode, "" +} + +// handleSSEInternalError is a convenience wrapper for SSE internal errors +func handleSSEInternalError(sseType string, operation string, err error) (string, s3err.ErrorCode, string) { + return handleSSEError(sseType, operation, err, s3err.ErrInternalError) +} |
