Unhandled parsing errors
Log from openshift:
"2023-11-21 09:00:43+0100|ERROR|jobsearch|MESSAGE: Exception on /search [GET]\rTraceback (most recent call last):\r File \"/usr/local/lib/python3.10/site-packages/flask/app.py\", line 1516, in full_dispatch_request\r rv = self.dispatch_request()\r File \"/usr/local/lib/python3.10/site-packages/flask/app.py\", line 1502, in dispatch_request\r return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)\r File \"/usr/local/lib/python3.10/site-packages/flask_restx/api.py\", line 404, in wrapper\r resp = resource(*args, **kwargs)\r File \"/usr/local/lib/python3.10/site-packages/flask/views.py\", line 84, in view\r return current_app.ensure_sync(self.dispatch_request)(*args, **kwargs)\r File \"/usr/local/lib/python3.10/site-packages/flask_restx/resource.py\", line 46, in dispatch_request\r resp = meth(*args, **kwargs)\r File \"/usr/local/lib/python3.10/site-packages/flask_restx/marshalling.py\", line 244, in wrapper\r resp = f(*args, **kwargs)\r File \"/app/./search/rest/endpoint/jobsearch.py\", line 62, in get\r return search_endpoint(querybuilder_container.get(QueryBuilderType.JOBSEARCH_SEARCH), args, start_time)\r File \"/app/./search/rest/endpoint/common.py\", line 36, in search_endpoint\r result = search_for_ads(args,\r File \"/app/./search/common_search/ad_search.py\", line 19, in search_for_ads\r query_dsl = querybuilder.parse_args(args, x_fields)\r File \"/app/./search/common_search/querybuilder.py\", line 103, in parse_args\r must_queries.append(self._filter_timeframe(args.get(constants.PUBLISHED_AFTER),\r File \"/app/./search/common_search/querybuilder.py\", line 883, in _filter_timeframe\r from_datetime = parser.parse(from_datestring)\r File \"/usr/local/lib/python3.10/site-packages/dateutil/parser/_parser.py\", line 1368, in parse\r return DEFAULTPARSER.parse(timestr, **kwargs)\r File \"/usr/local/lib/python3.10/site-packages/dateutil/parser/_parser.py\", line 643, in parse\r raise ParserError(\"Unknown string format: %s\", timestr)\rdateutil.parser._parser.ParserError: Unknown string format: 2022-05-22T12:20:52 fm",
Test to reproduce, put it in a file in tests/api_tests/searching/common
:
from tests.test_resources.helper import get_search
from requests import HTTPError
date_str_with_errors = "2022-05-22T12:20:52 fm"
def test_date_str_with_errors():
try:
params = {"published-after": date_str_with_errors}
response = get_search(params)
except HTTPError as e:
assert e.response.status_code == 500
raise
- Catch the error and log it in a better way. One line with a descriptive error message.
- Log level? It's a handled error, so maybe WARNING is the correct level?
- A parsing error should result in a 400/Bad Request response in the api.