Skip to content

Commit

Permalink
mnt: catch newly raised UnknownStationException
Browse files Browse the repository at this point in the history
  • Loading branch information
akrherz committed Dec 13, 2023
1 parent 6f61a02 commit f2dbe8d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions htdocs/plotting/auto/autoplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
import pandas as pd
from pandas.api.types import is_datetime64_any_dtype as isdt
from PIL import Image
from pyiem.exceptions import IncompleteWebRequest, NoDataFound
from pyiem.exceptions import (
IncompleteWebRequest,
NoDataFound,
UnknownStationException,
)
from pyiem.plot.use_agg import plt
from pyiem.util import utc
from pyiem.webutil import iemapp
Expand All @@ -29,6 +33,7 @@

HTTP200 = "200 OK"
HTTP400 = "400 Bad Request"
HTTP404 = "404 Not Found"
HTTP500 = "500 Internal Server Error"
BASEDIR, WSGI_FILENAME = os.path.split(__file__)

Expand Down Expand Up @@ -108,11 +113,12 @@ def handle_error(exp, fmt, uri):
"""Handle errors"""
exc_type, exc_value, exc_traceback = sys.exc_info()
tb = traceback.extract_tb(exc_traceback)[-1]
sys.stderr.write(
f"URI:{uri} {exp.__class__.__name__} "
f"method:{tb[2]} lineno:{tb[1]} {exp}\n"
)
if not isinstance(exp, NoDataFound):
if not isinstance(exp, UnknownStationException):
sys.stderr.write(
f"URI:{uri} {exp.__class__.__name__} "
f"method:{tb[2]} lineno:{tb[1]} {exp}\n"
)
if not isinstance(exp, (NoDataFound, UnknownStationException)):
traceback.print_exc()
del (exc_type, exc_value, exc_traceback, tb)
if fmt in ["png", "svg", "pdf"]:
Expand Down Expand Up @@ -208,6 +214,8 @@ def workflow(mc, environ, fmt):
# res should be a 3 length tuple
try:
res, meta = get_res_by_fmt(scriptnum, fmt, fdict)
except UnknownStationException as exp:
return HTTP404, handle_error(exp, fmt, environ.get("REQUEST_URI"))
except NoDataFound as exp:
return HTTP400, handle_error(exp, fmt, environ.get("REQUEST_URI"))
except Exception as exp:
Expand Down

0 comments on commit f2dbe8d

Please sign in to comment.