wstrinz / lesser-weather-potion

Simpler Plug based forecast bot
0 stars 0 forks source link

JSON parser error when call /webhook #1

Open duytruong opened 7 years ago

duytruong commented 7 years ago

Hi @wstrinz I got a problem when called the /webhook endpoint, here is the stack trace

Server: localhost:4000 (http)
Request: POST /webhook
** (exit) an exception was raised:
    ** (ArgumentError) JSON parser expects a :json_decoder option
        (plug) lib/plug/parsers/json.ex:17: Plug.Parsers.JSON.parse/5
        (plug) lib/plug/parsers.ex:210: Plug.Parsers.reduce/6
        (weatherbot) lib/weatherbot/router.ex:1: Weatherbot.Router.plug_builder_call/2
        (weatherbot) lib/plug/debugger.ex:123: Weatherbot.Router.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

I think I miss an option for json decode but I don't know exactly what it is and how to configure. I'm just a starter in Elixir.

wstrinz commented 7 years ago

Hi @duytruong , thanks for checking the project out!

I had some work on a separate branch that I've just merged in to master, can you pull the latest changes down and let me know if you're still having the problem.

Also I'm not sure how you ran across the project, but if it wasn't by way of the blog post tutorials I wrote around it you might want to give those a look for troubleshooting

duytruong commented 7 years ago

Hi @wstrinz, I've pulled the latest code but I'm still having the problem.

I actually followed your tutorials first, when I got the problem, I found this repo and tried to run your code but I got the same error.

After some googling, I change plug Plug.Parsers in lib/weatherbot/router.ex as follows:

  plug Plug.Parsers, parsers: [:json, :urlencoded], json_decoder: Poison

and it's working now, I don't know why I have to add json_decoder: Poison, but you don't.

My environment: Elixir 1.4.1, Erlang/OTP 19 [erts-8.3] and Ubuntu 16.04 LTS 64 bit