Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle exception and error for each middleware #1

Open
lord63 opened this issue Jun 17, 2015 · 1 comment
Open

How to handle exception and error for each middleware #1

lord63 opened this issue Jun 17, 2015 · 1 comment

Comments

@lord63
Copy link
Owner

lord63 commented Jun 17, 2015

No description provided.

@lord63
Copy link
Owner Author

lord63 commented Jun 17, 2015

I've given it a try for the github middleware: github.py:

@github_api.route(path)
@cache.cached(timeout=300)
def github():
    # TODO: how to handle exception and error, see issue#1.
    try:
        response = requests.get(
            'https://api.github.com/users/{0}/events/public'.format(username))
    except requests.RequestException as error:
        return jsonify(error_message=str(error.message))
    if response.status_code == 200:
        return jsonify(github=response.json())
    else:
        return jsonify(status_code=response.status_code)

The original node.js version of github: github.js and util.js

It seems that it will return 500 status code and the error message if something wrong.

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant