cfpb / regulations-site

(DEPRECATED) Web interface for viewing U.S. federal regulations and other regulatory information
Other
28 stars 43 forks source link

Properly catch TypeErrors in redirect_by_date_get #821

Closed chosak closed 7 years ago

chosak commented 7 years ago

A 500 error occurs when querying a redirect URL without all date components (year, month, day), e.g.

http://www.consumerfinance.gov/eregulations/regulation_redirect/1004-4

This is because TypeErrors aren't properly caught. See Python 2 docs:

Note that the parentheses around this tuple are required, because except ValueError, e: was the syntax used for what is normally written as except ValueError as e: in modern Python (described below). The old syntax is still supported for backwards compatibility. This means except RuntimeError, TypeError is not equivalent to except (RuntimeError, TypeError): but to except RuntimeError as TypeError: which is not what you want.