Comments (3)
Could you add some logging near here to figure out what is being returned as the request body and why on that version? https://github.com/fanduel/jsonrpc2-elixir/blob/master/lib/jsonrpc2/servers/http/plug.ex#L25
from jsonrpc2-elixir.
Thank you @ericentin I did some IO.inspects there like this, for reference:
def call(%{method: "POST"} = conn, handler) do
IO.inspect conn
req_body =
cond do <snip> end
|> IO.inspect
resp_body =
case <snip> end
|> IO.inspect
conn
|> Plug.Conn.put_resp_header("content-type", "application/json")
|> Plug.Conn.resp(200, resp_body)
|> IO.inspect
end
I run a correct query and then a failing one (first curl, then httpie)
Inspects for the working request (curl / plain/text
):
%Plug.Conn{
adapter: {Plug.Adapters.Cowboy.Conn, :...},
assigns: %{},
before_send: [],
body_params: %Plug.Conn.Unfetched{aspect: :body_params},
cookies: %Plug.Conn.Unfetched{aspect: :cookies},
halted: false,
host: "localhost",
method: "POST",
owner: #PID<0.676.0>,
params: %Plug.Conn.Unfetched{aspect: :params},
path_info: [],
path_params: %{},
peer: {{127, 0, 0, 1}, 43604},
port: 9656,
private: %{},
query_params: %Plug.Conn.Unfetched{aspect: :query_params},
query_string: "",
remote_ip: {127, 0, 0, 1},
req_cookies: %Plug.Conn.Unfetched{aspect: :cookies},
req_headers: [
{"host", "localhost:9656"},
{"user-agent", "curl/7.47.0"},
{"accept", "*/*"},
{"content-length", "75"},
{"content-type", "application/x-www-form-urlencoded"}
],
request_path: "/",
resp_body: nil,
resp_cookies: %{},
resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}],
scheme: :http,
script_name: [],
secret_key_base: nil,
state: :unset,
status: nil
}
"{\"params\":{\"transaction\": \"\"}, \"method\": \"submit\", \"jsonrpc\": \"2.0\",\"id\":0}"
"{\"jsonrpc\":\"2.0\",\"id\":0,\"error\":{\"message\":\"Internal error\",\"data\":\"malformed_transaction\",\"code\":-32603}}"
%Plug.Conn{
adapter: {Plug.Adapters.Cowboy.Conn, :...},
assigns: %{},
before_send: [],
body_params: %Plug.Conn.Unfetched{aspect: :body_params},
cookies: %Plug.Conn.Unfetched{aspect: :cookies},
halted: false,
host: "localhost",
method: "POST",
owner: #PID<0.676.0>,
params: %Plug.Conn.Unfetched{aspect: :params},
path_info: [],
path_params: %{},
peer: {{127, 0, 0, 1}, 43604},
port: 9656,
private: %{},
query_params: %Plug.Conn.Unfetched{aspect: :query_params},
query_string: "",
remote_ip: {127, 0, 0, 1},
req_cookies: %Plug.Conn.Unfetched{aspect: :cookies},
req_headers: [
{"host", "localhost:9656"},
{"user-agent", "curl/7.47.0"},
{"accept", "*/*"},
{"content-length", "75"},
{"content-type", "application/x-www-form-urlencoded"}
],
request_path: "/",
resp_body: "{\"jsonrpc\":\"2.0\",\"id\":0,\"error\":{\"message\":\"Internal error\",\"data\":\"malformed_transaction\",\"code\":-32603}}",
resp_cookies: %{},
resp_headers: [
{"cache-control", "max-age=0, private, must-revalidate"},
{"content-type", "application/json"}
],
scheme: :http,
script_name: [],
secret_key_base: nil,
state: :set,
status: 200
}
Inspects for the failing request (httpie / application/json
):
%Plug.Conn{
adapter: {Plug.Adapters.Cowboy.Conn, :...},
assigns: %{},
before_send: [],
body_params: %Plug.Conn.Unfetched{aspect: :body_params},
cookies: %Plug.Conn.Unfetched{aspect: :cookies},
halted: false,
host: "localhost",
method: "POST",
owner: #PID<0.677.0>,
params: %Plug.Conn.Unfetched{aspect: :params},
path_info: [],
path_params: %{},
peer: {{127, 0, 0, 1}, 43606},
port: 9656,
private: %{},
query_params: %Plug.Conn.Unfetched{aspect: :query_params},
query_string: "",
remote_ip: {127, 0, 0, 1},
req_cookies: %Plug.Conn.Unfetched{aspect: :cookies},
req_headers: [
{"host", "localhost:9656"},
{"accept", "application/json, */*"},
{"user-agent", "HTTPie/0.9.9"},
{"accept-encoding", "gzip, deflate"},
{"connection", "keep-alive"},
{"content-type", "application/json"},
{"content-length", "58"}
],
request_path: "/",
resp_body: nil,
resp_cookies: %{},
resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}],
scheme: :http,
script_name: [],
secret_key_base: nil,
state: :unset,
status: nil
}
%Plug.Conn.Unfetched{aspect: :params}
"{\"jsonrpc\":\"2.0\",\"id\":null,\"error\":{\"message\":\"Invalid Request\",\"code\":-32600}}"
%Plug.Conn{
adapter: {Plug.Adapters.Cowboy.Conn, :...},
assigns: %{},
before_send: [],
body_params: %Plug.Conn.Unfetched{aspect: :body_params},
cookies: %Plug.Conn.Unfetched{aspect: :cookies},
halted: false,
host: "localhost",
method: "POST",
owner: #PID<0.677.0>,
params: %Plug.Conn.Unfetched{aspect: :params},
path_info: [],
path_params: %{},
peer: {{127, 0, 0, 1}, 43606},
port: 9656,
private: %{},
query_params: %Plug.Conn.Unfetched{aspect: :query_params},
query_string: "",
remote_ip: {127, 0, 0, 1},
req_cookies: %Plug.Conn.Unfetched{aspect: :cookies},
req_headers: [
{"host", "localhost:9656"},
{"accept", "application/json, */*"},
{"user-agent", "HTTPie/0.9.9"},
{"accept-encoding", "gzip, deflate"},
{"connection", "keep-alive"},
{"content-type", "application/json"},
{"content-length", "58"}
],
request_path: "/",
resp_body: "{\"jsonrpc\":\"2.0\",\"id\":null,\"error\":{\"message\":\"Invalid Request\",\"code\":-32600}}",
resp_cookies: %{},
resp_headers: [
{"cache-control", "max-age=0, private, must-revalidate"},
{"content-type", "application/json"}
],
scheme: :http,
script_name: [],
secret_key_base: nil,
state: :set,
status: 200
}
The Plug.Conn.Unfetched{}
looks suspicious in the latter case, being the request body, and it is actually my handler that then produces the "Invalid request" and "32000". Isn't the condition cond
broken there, since conn.params != %Plug.Conn.Unfetched{}
and it == %Plug.Conn.Unfetched{something}
?
from jsonrpc2-elixir.
Fixes (hopefully) published as v1.1.1 on Hex
from jsonrpc2-elixir.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonrpc2-elixir.