Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

adjust the error output

Chris Lu310e31424e37
diff --git a/weed/s3api/s3err/error_handler.go b/weed/s3api/s3err/error_handler.go
index f176d4b6c8..09b83065f9 100644
--- a/weed/s3api/s3err/error_handler.go
+++ b/weed/s3api/s3err/error_handler.go
@@ -5,8 +5,10 @@ import (
"encoding/xml"
"fmt"
"github.com/chrislusf/seaweedfs/weed/glog"
+ "github.com/gorilla/mux"
"net/http"
"strconv"
+ "strings"
"time"
)
@@ -26,18 +28,27 @@ func WriteEmptyResponse(w http.ResponseWriter, statusCode int) {
}
func WriteErrorResponse(w http.ResponseWriter, errorCode ErrorCode, r *http.Request) {
+ vars := mux.Vars(r)
+ bucket := vars["bucket"]
+ object := vars["object"]
+ if !strings.HasPrefix(object, "/") {
+ object = "/" + object
+ }
+
apiError := GetAPIError(errorCode)
- errorResponse := getRESTErrorResponse(apiError, r.URL.Path)
+ errorResponse := getRESTErrorResponse(apiError, r.URL.Path, bucket, object)
encodedErrorResponse := EncodeXMLResponse(errorResponse)
WriteResponse(w, apiError.HTTPStatusCode, encodedErrorResponse, MimeXML)
}
-func getRESTErrorResponse(err APIError, resource string) RESTErrorResponse {
+func getRESTErrorResponse(err APIError, resource string, bucket, object string) RESTErrorResponse {
return RESTErrorResponse{
- Code: err.Code,
- Message: err.Description,
- Resource: resource,
- RequestID: fmt.Sprintf("%d", time.Now().UnixNano()),
+ Code: err.Code,
+ BucketName: bucket,
+ Key: object[1:],
+ Message: err.Description,
+ Resource: resource,
+ RequestID: fmt.Sprintf("%d", time.Now().UnixNano()),
}
}
diff --git a/weed/s3api/s3err/s3api_errors.go b/weed/s3api/s3err/s3api_errors.go
index 7f0ffdf863..a46bd0f045 100644
--- a/weed/s3api/s3err/s3api_errors.go
+++ b/weed/s3api/s3err/s3api_errors.go
@@ -15,11 +15,13 @@ type APIError struct {
// RESTErrorResponse - error response format
type RESTErrorResponse struct {
- XMLName xml.Name `xml:"Error" json:"-"`
- Code string `xml:"Code" json:"Code"`
- Message string `xml:"Message" json:"Message"`
- Resource string `xml:"Resource" json:"Resource"`
- RequestID string `xml:"RequestId" json:"RequestId"`
+ XMLName xml.Name `xml:"Error" json:"-"`
+ Code string `xml:"Code" json:"Code"`
+ Message string `xml:"Message" json:"Message"`
+ Resource string `xml:"Resource" json:"Resource"`
+ RequestID string `xml:"RequestId" json:"RequestId"`
+ Key string `xml:"Key,omitempty" json:"Key,omitempty"`
+ BucketName string `xml:"BucketName,omitempty" json:"BucketName,omitempty"`
// Underlying HTTP status code for the returned error
StatusCode int `xml:"-" json:"-"`