[#305] Fix UnknownAPIRequest handling

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-01-17 15:14:51 +03:00 committed by Angira Kekteeva
parent a461feab01
commit 097f745d3e

View file

@ -136,7 +136,7 @@ func WriteErrorResponse(w http.ResponseWriter, reqInfo *ReqInfo, err error) {
func errorResponseHandler(w http.ResponseWriter, r *http.Request) { func errorResponseHandler(w http.ResponseWriter, r *http.Request) {
desc := fmt.Sprintf("Unknown API request at %s", r.URL.Path) desc := fmt.Sprintf("Unknown API request at %s", r.URL.Path)
WriteErrorResponse(w, GetReqInfo(r.Context()), errors.Error{ WriteErrorResponse(w, GetReqInfo(r.Context()), errors.Error{
Code: "XMinioUnknownAPIRequest", Code: "UnknownAPIRequest",
Description: desc, Description: desc,
HTTPStatusCode: http.StatusBadRequest, HTTPStatusCode: http.StatusBadRequest,
}) })
@ -235,12 +235,17 @@ func getAPIErrorResponse(info *ReqInfo, err error) ErrorResponse {
desc = e.Description desc = e.Description
} }
var resource string
if info.URL != nil {
resource = info.URL.Path
}
return ErrorResponse{ return ErrorResponse{
Code: code, Code: code,
Message: desc, Message: desc,
BucketName: info.BucketName, BucketName: info.BucketName,
Key: info.ObjectName, Key: info.ObjectName,
Resource: info.URL.Path, Resource: resource,
RequestID: info.RequestID, RequestID: info.RequestID,
HostID: info.DeploymentID, HostID: info.DeploymentID,
} }