[NOD-464] Fix error messages in GetBlocks. (#500)

This commit is contained in:
stasatdaglabs 2019-11-28 17:31:19 +02:00 committed by Svarog
parent bdc3cbceaa
commit 5e9fc2defc

View File

@ -86,7 +86,11 @@ func convertQueryParamToInt(queryParams map[string]string, param string, default
if _, ok := queryParams[param]; ok { if _, ok := queryParams[param]; ok {
intValue, err := strconv.Atoi(queryParams[param]) intValue, err := strconv.Atoi(queryParams[param])
if err != nil { if err != nil {
return 0, httpserverutils.NewHandlerError(http.StatusUnprocessableEntity, errors.Wrap(err, fmt.Sprintf("Couldn't parse the '%s' query parameter", param))) errorMessage := fmt.Sprintf("Couldn't parse the '%s' query parameter", param)
return 0, httpserverutils.NewHandlerErrorWithCustomClientMessage(
http.StatusUnprocessableEntity,
errors.Wrap(err, errorMessage),
errorMessage)
} }
return intValue, nil return intValue, nil
} }
@ -159,7 +163,8 @@ func getBlocksHandler(_ *httpserverutils.ServerContext, _ *http.Request, _ map[s
order := defaultGetBlocksOrder order := defaultGetBlocksOrder
if orderParamValue, ok := queryParams[queryParamOrder]; ok { if orderParamValue, ok := queryParams[queryParamOrder]; ok {
if orderParamValue != controllers.OrderAscending && orderParamValue != controllers.OrderDescending { if orderParamValue != controllers.OrderAscending && orderParamValue != controllers.OrderDescending {
return nil, httpserverutils.NewHandlerError(http.StatusUnprocessableEntity, errors.Errorf("'%s' is not a valid value for the '%s' query parameter", orderParamValue, queryParamLimit)) return nil, httpserverutils.NewHandlerError(http.StatusUnprocessableEntity, errors.Errorf(
"Couldn't parse the '%s' query parameter", queryParamLimit))
} }
order = orderParamValue order = orderParamValue
} }