avoid possible empty object

This commit is contained in:
Chris Lu 2021-06-10 22:17:53 -07:00
parent 310e31424e
commit b71c3cfba4

View file

@ -31,8 +31,8 @@ func WriteErrorResponse(w http.ResponseWriter, errorCode ErrorCode, r *http.Requ
vars := mux.Vars(r)
bucket := vars["bucket"]
object := vars["object"]
if !strings.HasPrefix(object, "/") {
object = "/" + object
if strings.HasPrefix(object, "/") {
object = object[1:]
}
apiError := GetAPIError(errorCode)
@ -45,7 +45,7 @@ func getRESTErrorResponse(err APIError, resource string, bucket, object string)
return RESTErrorResponse{
Code: err.Code,
BucketName: bucket,
Key: object[1:],
Key: object,
Message: err.Description,
Resource: resource,
RequestID: fmt.Sprintf("%d", time.Now().UnixNano()),