Skip to content

Commit e9ba40e

Browse files
committed
accept any term as reason of api error
1 parent e804d06 commit e9ba40e

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ The library uses [escript](http://erlang.org/doc/man/escript.html) executables t
2626

2727
The latest version of the library is available at its `master` branch. All development, including new features and bug fixes, take place on the `master` branch using forking and pull requests as described in contribution guidelines.
2828

29-
Add the library as dependency to rebar.config
29+
The stable library release is available via hex packages, add the library as dependency to rebar.config
30+
31+
```erlang
32+
{deps, [
33+
serverless
34+
]}.
35+
```
36+
37+
Latest development version is available at GitHuB, add the library as dependency to rebar.config
3038

3139
```erlang
3240
{deps, [

src/serverless_api.erl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
%%
1111
return({error, Reason}) ->
1212
{Code, _} = Error = error_code(Reason),
13+
Json = error_json(Error, Reason),
1314
serverless:error(#{
1415
api => error,
15-
reason => Reason,
16+
reason => Json,
1617
status => Code
1718
}),
18-
return({Code, error_json(Error, Reason)});
19+
return({Code, Json});
1920

2021
return({Code, Json}) when is_map(Json) orelse is_list(Json) ->
2122
return({Code, jsx:encode(Json)});
@@ -68,11 +69,15 @@ error_json({Code, Text}, Reason) ->
6869
error_reason({_, #{} = Reason}) ->
6970
Reason;
7071
error_reason({Reason, Details}) ->
71-
typecast:s([typecast:s(Reason), $:, $ , typecast:s(Details)]);
72+
erlang:iolist_to_binary(
73+
io_lib:format("~2048.p : ~2048.p", [Reason, Details])
74+
);
7275
error_reason(#{} = Reason) ->
7376
Reason;
7477
error_reason(Reason) ->
75-
typecast:s(Reason).
78+
erlang:iolist_to_binary(
79+
io_lib:format("~2048.p", [Reason])
80+
).
7681

7782

7883
%%

0 commit comments

Comments
 (0)