edgurgel/poxa

REST API not working for presence channel/users

Closed this issue ยท 3 comments

Hello, first off awesome work you've done.

I have successfully run the server with docker and manage to connect using javascript and pushing updates with PHP using the official sdk.

However, when doing the following REST call, I'm getting an 500 error in the server console.

GET /apps/[app_id]/channels/[channel_name]/users

I have also used Postman and cURL to make sure that there is nothing wrong with PHP SDK and still the same error.

http://localhost:8080/apps/id/channels/presence-3gr6vnyp8bk82peczp6w/users?auth_key=key&auth_signature=7622b015252705fa0eef6080af7fca8a2df3767b10d7f736162108d458d6ee8f&auth_timestamp=1530202801&auth_version=1.0

16:20:52.582 [error] Error in process #PID<0.1483.0> on node :"poxa@127.0.0.1" with exit value:
{[reason: %Poison.EncodeError{message: nil,
value: {:users, [[id: "1530201611"], [id: "1530202152"]]}},
mfa: {Poxa.UsersHandler, :get_json, 2},
stacktrace: [{Poison.Encoder.Any, :encode, 2,
[file: 'lib/poison/encoder.ex', line: 383]},
{Poison.Encoder.List, :"-encode/3-fun-0-", 3,
[file: 'lib/poison/encoder.ex', line: 259]},
{Poison.Encoder.List, :encode, 3,
[file: 'lib/poison/encoder.ex', line: 260]},
{Poison, :encode!, 2, [file: 'lib/poison.ex', line: 41]},
{Poxa.UsersHandler, :get_json, 2,
[file: 'lib/poxa/users_handler.ex', line: 53]},
{:cowboy_rest, :call, 3,
[file: '/source/deps/cowboy/src/cowboy_rest.erl', line: 976]},
{:cowboy_rest, :set_resp_body, 2,
[file: '/source/deps/cowboy/src/cowboy_rest.erl', line: 858]},
{:cowboy_protocol, :execute, 4,
[file: '/source/deps/cowboy/src/cowboy_protocol.erl', line: 442]}],
req: [socket: #Port<0.2748>, transport: :ranch_tcp, connection: :keepalive,
pid: #PID<0.1483.0>, method: "GET", version: :"HTTP/1.1",
peer: {{172, 17, 0, 1}, 59504}, host: "localhost", host_info: :undefined,
port: 8080, path: "/apps/id/channels/presence-3gr6vnyp8bk82peczp6w/users",
path_info: :undefined,
qs: "auth_key=key&auth_signature=7622b015252705fa0eef6080af7fca8a2df3767b10d7f736162108d458d6ee8f&auth_timestamp=1530202801&auth_version=1.0",
qs_vals: [{"auth_key", "key"},
{"auth_signature",
"7622b015252705fa0eef6080af7fca8a2df3767b10d7f736162108d458d6ee8f"},
{"auth_timestamp", "1530202801"}, {"auth_version", "1.0"}],
bindings: [channel_name: "presence-3gr6vnyp8bk82peczp6w", app_id: "id"],
headers: [{"cache-control", "no-cache"},
{"postman-token", "f04eecea-f855-41a3-8fef-5018984cb30e"},
{"user-agent", "PostmanRuntime/7.1.5"}, {"accept", "/"},
{"host", "localhost:8080"}, {"accept-encoding", "gzip, deflate"},
{"connection", "keep-alive"}],
p_headers: [{"if-modified-since", :undefined}, {"if-none-match", :undefined},
{"if-unmodified-since", :undefined}, {"if-match", :undefined},
{"accept", [{{"", "", []}, 1000, []}]}, {"content-length", 0},
{"transfer-encoding", ["identity"]}, {"expect", :undefined},
{"connection", ["keep-alive"]}], cookies: :undefined,
meta: [media_type: {"application", "json", []}, charset: :undefined],
body_state: :done, buffer: "", multipart: :undefined, resp_compress: false,
resp_state: :waiting,
resp_headers: [{"content-type", ["application", "/", "json", ""]}],
resp_body: "", onresponse: :undefined],
state: "presence-3gr6vnyp8bk82peczp6w"],
[{:cowboy_rest, :error_terminate, 5,
[file: '/source/deps/cowboy/src/cowboy_rest.erl', line: 1009]},
{:cowboy_rest, :set_resp_body, 2,
[file: '/source/deps/cowboy/src/cowboy_rest.erl', line: 858]},
{:cowboy_protocol, :execute, 4,
[file: '/source/deps/cowboy/src/cowboy_protocol.erl', line: 442]}]}

16:20:52.590 [error] Ranch listener :poxa had connection process started with :cowboy_protocol:start_link/4 at #PID<0.1483.0> exit with reason: {[reason: %Poison.EncodeError{message: nil, value: {:users, [[id: "1530201611"], [id: "1530202152"]]}}, mfa: {Poxa.UsersHandler, :get_json, 2}, stacktrace: [{Poison.Encoder.Any, :encode, 2, [file: 'lib/poison/encoder.ex', line: 383]}, {Poison.Encoder.List, :"-encode/3-fun-0-", 3, [file: 'lib/poison/encoder.ex', line: 259]}, {Poison.Encoder.List, :encode, 3, [file: 'lib/poison/encoder.ex', line: 260]}, {Poison, :encode!, 2, [file: 'lib/poison.ex', line: 41]}, {Poxa.UsersHandler, :get_json, 2, [file: 'lib/poxa/users_handler.ex', line: 53]}, {:cowboy_rest, :call, 3, [file: '/source/deps/cowboy/src/cowboy_rest.erl', line: 976]}, {:cowboy_rest, :set_resp_body, 2, [file: '/source/deps/cowboy/src/cowboy_rest.erl', line: 858]}, {:cowboy_protocol, :execute, 4, [file: '/source/deps/cowboy/src/cowboy_protocol.erl', line: 442]}], req: [socket: #Port<0.2748>, transport: :ranch_tcp, connection: :keepalive, pid: #PID<0.1483.0>, method: "GET", version: :"HTTP/1.1", peer: {{172, 17, 0, 1}, 59504}, host: "localhost", host_info: :undefined, port: 8080, path: "/apps/id/channels/presence-3gr6vnyp8bk82peczp6w/users", path_info: :undefined, qs: "auth_key=key&auth_signature=7622b015252705fa0eef6080af7fca8a2df3767b10d7f736162108d458d6ee8f&auth_timestamp=1530202801&auth_version=1.0", qs_vals: [{"auth_key", "key"}, {"auth_signature", "7622b015252705fa0eef6080af7fca8a2df3767b10d7f736162108d458d6ee8f"}, {"auth_timestamp", "1530202801"}, {"auth_version", "1.0"}], bindings: [channel_name: "presence-3gr6vnyp8bk82peczp6w", app_id: "id"], headers: [{"cache-control", "no-cache"}, {"postman-token", "f04eecea-f855-41a3-8fef-5018984cb30e"}, {"user-agent", "PostmanRuntime/7.1.5"}, {"accept", "/"}, {"host", "localhost:8080"}, {"accept-encoding", "gzip, deflate"}, {"connection", "keep-alive"}], p_headers: [{"if-modified-since", :undefined}, {"if-none-match", :undefined}, {"if-unmodified-since", :undefined}, {"if-match", :undefined}, {"accept", [{{"", "", []}, 1000, []}]}, {"content-length", 0}, {"transfer-encoding", ["identity"]}, {"expect", :undefined}, {"connection", ["keep-alive"]}], cookies: :undefined, meta: [media_type: {"application", "json", []}, charset: :undefined], body_state: :done, buffer: "", multipart: :undefined, resp_compress: false, resp_state: :waiting, resp_headers: [{"content-type", ["application", "/", "json", ""]}], resp_body: "", onresponse: :undefined], state: "presence-3gr6vnyp8bk82peczp6w"], [{:cowboy_rest, :error_terminate, 5, [file: '/source/deps/cowboy/src/cowboy_rest.erl', line: 1009]}, {:cowboy_rest, :set_resp_body, 2, [file: '/source/deps/cowboy/src/cowboy_rest.erl', line: 858]}, {:cowboy_protocol, :execute, 4, [file: '/source/deps/cowboy/src/cowboy_protocol.erl', line: 442]}]}

Steps to reproduce

Run the server with docker

docker run --rm -p 8080:8080 --name poxa -e POXA_APP_KEY=key -e POXA_SECRET=secret -e POXA_APP_ID=id edgurgel/poxa-automated

Call the REST Api.

curl -X GET \
  'http://localhost:8080/apps/id/channels/presence-3gr6vnyp8bk82peczp6w/users?auth_key=key&auth_signature=7622b015252705fa0eef6080af7fca8a2df3767b10d7f736162108d458d6ee8f&auth_timestamp=1530202801&auth_version=1.0' \
  -H 'Cache-Control: no-cache' \
  -H 'Postman-Token: 62f524bd-3634-46be-872d-c0c62b692c9d'

If you need any other information or tests, let me know

Thank you

Thanks for the bug report. I think I know what's the issue. It's probably related to the upgrade we on our JSON encoding lib. I will fix this issue this weekend.

And also add an integration test :)

@edgurgel just to let you know that v0.7.5 is working as expected, thank you for the quick fix. ๐Ÿ‘

Thanks for the feedback! :)