Skip to content

Commit

Permalink
Add generic error handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Jan 22, 2020
1 parent 4cab800 commit c9a1b6f
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion chord_service_registry/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import os
import requests
import sys
import traceback

from chord_lib.responses.flask_errors import flask_not_found_error
from chord_lib.responses.flask_errors import *
from flask import Flask, json, jsonify
from urllib.parse import urljoin
from werkzeug.exceptions import BadRequest, NotFound


TIMEOUT = 1
Expand Down Expand Up @@ -40,6 +42,26 @@
application.config.from_mapping(CHORD_SERVICES=CHORD_SERVICES_PATH)


# TODO: Figure out common pattern and move to chord_lib

def _wrap_tb(func): # pragma: no cover
# TODO: pass exception?
def handle_error(_e):
print("[CHORD Service Registry] Encountered error:", file=sys.stderr)
traceback.print_exc()
return func()
return handle_error


def _wrap(func): # pragma: no cover
return lambda _e: func()


application.register_error_handler(Exception, _wrap_tb(flask_internal_server_error)) # Generic catch-all
application.register_error_handler(BadRequest, _wrap(flask_bad_request_error))
application.register_error_handler(NotFound, _wrap(flask_not_found_error))


service_info_cache = {}


Expand Down

0 comments on commit c9a1b6f

Please sign in to comment.