mirror of
https://github.com/valitydev/capi-v2.git
synced 2024-11-06 01:55:20 +00:00
impl callback map_error() (#476)
This commit is contained in:
parent
b704db562d
commit
0268dbeba4
2
Makefile
2
Makefile
@ -19,7 +19,7 @@ SERVICE_IMAGE_PUSH_TAG ?= $(SERVICE_IMAGE_TAG)
|
||||
BASE_IMAGE_NAME := service-erlang
|
||||
BASE_IMAGE_TAG := da0ab769f01b650b389d18fc85e7418e727cbe96
|
||||
|
||||
BUILD_IMAGE_TAG := 442c2c274c1d8e484e5213089906a4271641d95e
|
||||
BUILD_IMAGE_TAG := 0c638a682f4735a65ef232b81ed872ba494574c3
|
||||
|
||||
CALL_ANYWHERE := \
|
||||
submodules \
|
||||
|
@ -2,8 +2,11 @@
|
||||
|
||||
-behaviour(swag_server_logic_handler).
|
||||
|
||||
-type error_type() :: swag_server_logic_handler:error_type().
|
||||
|
||||
%% API callbacks
|
||||
-export([authorize_api_key/3]).
|
||||
-export([map_error/2]).
|
||||
-export([handle_request/4]).
|
||||
|
||||
%% Handler behaviour
|
||||
@ -39,6 +42,26 @@ authorize_api_key(OperationID, ApiKey, _HandlerOpts) ->
|
||||
false
|
||||
end.
|
||||
|
||||
-spec map_error(error_type(), swag_server_validation:error()) ->
|
||||
swag_server:error_reason().
|
||||
|
||||
map_error(validation_error, Error) ->
|
||||
Type = genlib:to_binary(maps:get(type, Error)),
|
||||
Name = genlib:to_binary(maps:get(param_name, Error)),
|
||||
Message = case maps:get(description, Error, undefined) of
|
||||
undefined ->
|
||||
<<"Request parameter: ", Name/binary, ", error type: ", Type/binary>>;
|
||||
Description ->
|
||||
DescriptionBin = genlib:to_binary(Description),
|
||||
<<"Request parameter: ", Name/binary,
|
||||
", error type: ", Type/binary,
|
||||
", description: ", DescriptionBin/binary>>
|
||||
end,
|
||||
jsx:encode(#{
|
||||
<<"code">> => <<"invalidRequest">>,
|
||||
<<"message">> => Message
|
||||
}).
|
||||
|
||||
-type request_data() :: #{atom() | binary() => term()}.
|
||||
|
||||
-type operation_id() :: swag_server:operation_id().
|
||||
|
Loading…
Reference in New Issue
Block a user