data61 / Mirza

6 stars 2 forks source link

BR: Investigate Improving JSON Formatting Errors #348

Open a-stacey opened 5 years ago

a-stacey commented 5 years ago

The JSON formatting errors aren't particularly descriptive or useful for the underlying issue.

For instance the following is a malformed JSON query:

curl -X POST "http://localhost:8200/user/add" -H  "accept: application/json;charset=utf-8" -H  "Content-Type: application/json;charset=utf-8" -d "{  \"newUserEmailAddress\": \"email1@example.com\",  \"newUserPassword\": \"test\",  \"newUserCompany\": \"prefix\"  \"newUserFirstName\": \"firstname\",  \"newUserLastName\": \"lastname\",  \"newUserPhoneNumber\": \"(02) 1234 5678\"}" -i -u user@example.com:password

Returns the error:

HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
Date: Wed, 09 Jan 2019 00:02:45 GMT
Server: Warp/3.2.22

Failed reading: satisfy

Which is not exactly intuative...the error is that the JSON is malformed and that the , is missing between "prefix" and "newUserFirstName" so "prefix", "newUserFirstName". E.g. the following works:

curl -X POST "http://localhost:8200/user/add" -H  "accept: application/json;charset=utf-8" -H  "Content-Type: application/json;charset=utf-8" -d "{  \"newUserEmailAddress\": \"email1@example.com\",  \"newUserPassword\": \"test\",  \"newUserCompany\": \"prefix\",  \"newUserFirstName\": \"firstname\",  \"newUserLastName\": \"lastname\",  \"newUserPhoneNumber\": \"(02) 1234 5678\"}" -i -u user@example.com:password
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Wed, 09 Jan 2019 00:05:06 GMT
Server: Warp/3.2.22
Content-Type: application/json;charset=utf-8

"33460082-666d-4340-82e3-ec81a7544974"
a-stacey commented 5 years ago

Related: https://github.com/data61/Mirza/issues/270