SmartCambridge / tfc_web

Web access to the TFC platform
MIT License
3 stars 2 forks source link

HTTPError at /traffic/zone/plot/transit/<zone>/ Exception Value: HTTP Error 400: Bad Request #314

Open jw35 opened 5 years ago

jw35 commented 5 years ago
Traceback:  

File "/home/tfc_prod/tfc_web_venv/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
 41.             response = get_response(request)

File "/home/tfc_prod/tfc_web_venv/lib/python3.5/site-packages/django/core/handlers/base.py" in _legacy_get_response
 249.             response = self._get_response(request)

File "/home/tfc_prod/tfc_web_venv/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
 187.                 response = self.process_exception_by_middleware(e, request)

File "/home/tfc_prod/tfc_web_venv/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
 185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/tfc_prod/tfc_web/tfc_web/traffic/views.py" in zone_transit_plot
 60.             raise e

File "/home/tfc_prod/tfc_web/tfc_web/traffic/views.py" in zone_transit_plot
 54.         transit_json = get_zone_history(zone_id, user_date)

File "/home/tfc_prod/tfc_web/tfc_web/traffic/views.py" in get_zone_history
 34.             '?start_date=' + date)

File "/home/tfc_prod/tfc_web/tfc_web/api/util.py" in do_api_call
 147.     return  json.load(reader(urlopen(query)))

File "/usr/lib/python3.5/urllib/request.py" in urlopen
 163.     return opener.open(url, data, timeout)

File "/usr/lib/python3.5/urllib/request.py" in open
 472.             response = meth(req, response)

File "/usr/lib/python3.5/urllib/request.py" in http_response
 582.                 'http', request, response, code, msg, hdrs)

File "/usr/lib/python3.5/urllib/request.py" in error
 504.         result = self._call_chain(*args)

File "/usr/lib/python3.5/urllib/request.py" in _call_chain
 444.             result = func(*args)

File "/usr/lib/python3.5/urllib/request.py" in http_error_302
 696.         return self.parent.open(new, timeout=req.timeout)

File "/usr/lib/python3.5/urllib/request.py" in open
 472.             response = meth(req, response)

File "/usr/lib/python3.5/urllib/request.py" in http_response
 582.                 'http', request, response, code, msg, hdrs)

File "/usr/lib/python3.5/urllib/request.py" in error
 510.             return self._call_chain(*args)

File "/usr/lib/python3.5/urllib/request.py" in _call_chain
 444.             result = func(*args)

File "/usr/lib/python3.5/urllib/request.py" in http_error_default
 590.         raise HTTPError(req.full_url, code, msg, hdrs, fp)

Exception Type: HTTPError at /traffic/zone/plot/transit/madingley_road_outer_in/
Exception Value: HTTP Error 400: Bad Request
Request information:
USER: AnonymousUser

GET:
date = '2019-04-26)'
jw35 commented 5 years ago

This was caused by a bogus ')' on the end of the date parameter, which caused the API to throw an exception. But IMO we shouldn't throw exceptions in response to bogus user input since there's nothing we can do about it.

So, this

https://github.com/SmartCambridge/tfc_web/blob/4dd9c0500216bfbfc1d34164388b208faf57ab01/tfc_web/traffic/views.py#L53-L60

really needs to handle at least 400 as well as 404. This may be true for API calls elsewhere in transport, aq, and parking...