예제 #1
0
def report_alert(alert_type: str,
                 resp: Response,
                 title: str = "Error",
                 description: str = ""):
    if not hasattr(resp, "alerts"):
        resp.alerts = []

    resp.alerts.append({
        "title": title,
        "type": alert_type,
        "description": description
    })
예제 #2
0
def _handle_exceptions(ex: Exception, resp: falcon.Response):
    logging.debug("Handling exception: %s", repr(ex))

    if not hasattr(resp, "alerts"):
        resp.alerts = []

    if isinstance(ex, (falcon.HTTPPermanentRedirect, falcon.HTTPSeeOther)):
        raise ex

    if isinstance(ex, (falcon.HTTPError, ValidationError)):
        report_error(resp=resp, title=ex.title, description=ex.description)
    elif isinstance(ex, urllib3.exceptions.RequestError):
        report_error(
            resp=resp,
            title="Server unavailable",
            description="The data server seems to be unavailable at the moment"
        )
    else:
        report_error(resp=resp, description=sys.exc_info()[1])