actix / examples

Community showcase and examples of Actix Web ecosystem usage.
Apache License 2.0
3.7k stars 807 forks source link

Json post examples don't return errors on invalid json #60

Closed Firstyear closed 5 years ago

Firstyear commented 5 years ago

When using the json post examples, misformed json returns no errors:

actix-examples/json I0> curl --header "Content-Type: application/json" --request POST --data '{ "invalid": "data" }'  http://127.0.0.1:8080/
actix-examples/json I0> echo $?
0

actix-examples/json I0> curl -i --header "Content-Type: application/json" --request POST --data '{ "invalid": "data" }'  http://127.0.0.1:8080/
HTTP/1.1 400 Bad Request
content-length: 0
date: Sun, 11 Nov 2018 23:43:04 GMT

 WARN 2018-11-11T23:41:00Z: actix_web::pipeline: Error occured during request handling: Json deserialize error: missing field `name` at line 1 column 21
 INFO 2018-11-11T23:41:00Z: actix_web::middleware::logger: 127.0.0.1:51680 "POST / HTTP/1.1" 400 0 "-" "curl/7.61.1" 0.001901

Curl should receive the message about why the json was invalid. This way the client can improve their behaviour on malformed requests.

The index_manual type is the most likely to be able to support this workflow.

fafhrd91 commented 5 years ago

fixed