Loris icon indicating copy to clipboard operation
Loris copied to clipboard

Incorrect error message with invalid date format

Open driusan opened this issue 3 years ago • 2 comments

Describe the bug Since 614b8d82117b434b3ae49827cb1302c99155b2a8 the LORIS API error out with an (HTML) 500 page if the date format is not 'YYYY-MM-DD' saying "Date of Birth must be specified" in the error logs. This is incorrect if the date is specified in another format, rather than missing (and should be a JSON error response instead of the generic LORIS 500 error page).

To Reproduce Post to the candidate API with a DoB in another date format

What did you expect to happen?

Either the date format is accepted, or an error message with the correct format is given to the API user. Instead, a 500 error is displayed to the user and an incorrect error message is displayed in the error logs.

driusan avatar Jun 22 '22 15:06 driusan

There is actually 2 issues here.

  1. The API should catch the Exception thrown by the Candidate class to return a JSON response appropriate to the error (in this case: 400 Bad Request if the provided date can't be parsed.)
  2. The format of the input date should not be restricted to YYYY-MM-DD

xlecours avatar Jun 22 '22 15:06 xlecours

On a side note:

curl -v -k -H "Authorization: Bearer $token" https://hostname/new_profile -F sex='male' -F dobDate='22-01-99' -F site=2 -F project=1

HTTP/1.1 400 Bad Request
Content-Type: application/json

{"error":"\u0022Date of Birth is not a valid date.\u0022"}

I am adding this to mention that that solution to the input date format issue should work for both /new_profile and /api/v0.0.3/candidates endpoints.

xlecours avatar Jun 22 '22 16:06 xlecours

Fixed by #8279

driusan avatar Dec 20 '22 17:12 driusan