Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Incorrect error message with invalid date format #8127

Closed
driusan opened this issue Jun 22, 2022 · 3 comments
Closed

Incorrect error message with invalid date format #8127

driusan opened this issue Jun 22, 2022 · 3 comments
Assignees
Labels
Bug PR or issue introducing/requiring bug fixes (not mutually exclusive with the Feature label)

Comments

@driusan
Copy link
Collaborator

driusan commented Jun 22, 2022

Describe the bug
Since 614b8d8 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 driusan added the Bug PR or issue introducing/requiring bug fixes (not mutually exclusive with the Feature label) label Jun 22, 2022
@xlecours
Copy link
Contributor

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
Copy link
Contributor

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.

regisoc added a commit that referenced this issue Sep 30, 2022
Several behaviors related to date parsing. When using `/new_profile` or
`/api/v0.0.3/candidates` to add candidates, date parsing allowed date
such as 0000-00-00 or with possible multiple separators when only
months were provided (e.g. 'yyyy/mm'). Only one format was really used
(i.e. 'yyyy-mm-dd' for sql compatibility).

This fix checks multiple date formats and 3 separators (i.e. '-', '/',
and '.'). E.g. some valid date formats: 'yyyy-mm', 'dd/mm/yyyy',
'yyyy-mm-dd'.
@driusan
Copy link
Collaborator Author

driusan commented Dec 20, 2022

Fixed by #8279

@driusan driusan closed this as completed Dec 20, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Bug PR or issue introducing/requiring bug fixes (not mutually exclusive with the Feature label)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants