Refactoring API router

- method to fetch request id
- middleware to set request id and info
- fixes for getAPIErrorResponse (fix possible NPE)

Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
Evgeniy Kulikov 2020-08-11 14:30:02 +03:00
parent 26f1df2721
commit 59e26d45fd
2 changed files with 170 additions and 66 deletions

View file

@ -1623,12 +1623,15 @@ func GetAPIError(code ErrorCode) Error {
// getErrorResponse gets in standard error and resource value and
// provides a encodable populated response values
func getAPIErrorResponse(ctx context.Context, err Error, resource, requestID, hostID string) ErrorResponse {
reqInfo := GetReqInfo(ctx)
info := GetReqInfo(ctx)
if info == nil {
info = &ReqInfo{}
}
return ErrorResponse{
Code: err.Code,
Message: err.Description,
BucketName: reqInfo.BucketName,
Key: reqInfo.ObjectName,
BucketName: info.BucketName,
Key: info.ObjectName,
Resource: resource,
RequestID: requestID,
HostID: hostID,