mirror of
https://github.com/chrislusf/seaweedfs
synced 2024-07-05 16:47:04 +02:00
adjust the error output
fix https://github.com/chrislusf/seaweedfs/issues/2123
This commit is contained in:
parent
8b382a8209
commit
310e31424e
|
@ -5,8 +5,10 @@ import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,18 +28,27 @@ func WriteEmptyResponse(w http.ResponseWriter, statusCode int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteErrorResponse(w http.ResponseWriter, errorCode ErrorCode, r *http.Request) {
|
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)
|
apiError := GetAPIError(errorCode)
|
||||||
errorResponse := getRESTErrorResponse(apiError, r.URL.Path)
|
errorResponse := getRESTErrorResponse(apiError, r.URL.Path, bucket, object)
|
||||||
encodedErrorResponse := EncodeXMLResponse(errorResponse)
|
encodedErrorResponse := EncodeXMLResponse(errorResponse)
|
||||||
WriteResponse(w, apiError.HTTPStatusCode, encodedErrorResponse, MimeXML)
|
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{
|
return RESTErrorResponse{
|
||||||
Code: err.Code,
|
Code: err.Code,
|
||||||
Message: err.Description,
|
BucketName: bucket,
|
||||||
Resource: resource,
|
Key: object[1:],
|
||||||
RequestID: fmt.Sprintf("%d", time.Now().UnixNano()),
|
Message: err.Description,
|
||||||
|
Resource: resource,
|
||||||
|
RequestID: fmt.Sprintf("%d", time.Now().UnixNano()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,13 @@ type APIError struct {
|
||||||
|
|
||||||
// RESTErrorResponse - error response format
|
// RESTErrorResponse - error response format
|
||||||
type RESTErrorResponse struct {
|
type RESTErrorResponse struct {
|
||||||
XMLName xml.Name `xml:"Error" json:"-"`
|
XMLName xml.Name `xml:"Error" json:"-"`
|
||||||
Code string `xml:"Code" json:"Code"`
|
Code string `xml:"Code" json:"Code"`
|
||||||
Message string `xml:"Message" json:"Message"`
|
Message string `xml:"Message" json:"Message"`
|
||||||
Resource string `xml:"Resource" json:"Resource"`
|
Resource string `xml:"Resource" json:"Resource"`
|
||||||
RequestID string `xml:"RequestId" json:"RequestId"`
|
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
|
// Underlying HTTP status code for the returned error
|
||||||
StatusCode int `xml:"-" json:"-"`
|
StatusCode int `xml:"-" json:"-"`
|
||||||
|
|
Loading…
Reference in a new issue