I am writing a webapp using Erlang toolchain (OTP, rebar3, cowboy, jsx...). The following code does not work because jsx:is_json/1
cannot be found during runtime.
handle_login(Req, State) ->
{ok, Data, _} = cowboy_req:body(Req),
case jsx:is_json(Data) of
false -> cowboy_req:reply(400,
[
{<<"content-type">>, <<"application/json">>}
],
<<"Invalid JSON">>,
Req);
Stacktrace:
{[{reason,undef},
{mfa,{erbid_api_handler,handle,2}},
{stacktrace,
[{jsx,is_json,[<<"{\"username\":\"tom\"}">>],[]},
{erbid_api_handler,handle_login,2,
[{file,
"/Users/khanhhua/dev/project-erbid/_build/default/lib/erbid/src/erbid_api_handler.erl"},
{line,45}]},
{erbid_api_handler,handle,2,
... truncated for brevity
I need to know how to fix the issue. Thanks.
I have found the cause of this issue. I did not not include module
jsx
in myerbid.app.src
's applications section.Totally due to my lack of Erlang experience.