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

[bug] unknown categories are not handled by an error #669

Closed
karlcow opened this issue Aug 10, 2015 · 5 comments
Closed

[bug] unknown categories are not handled by an error #669

karlcow opened this issue Aug 10, 2015 · 5 comments

Comments

@karlcow
Copy link
Member

karlcow commented Aug 10, 2015

@api.route('/issues/search/<issue_category>')
in https://github.com/webcompat/webcompat.com/blob/master/webcompat/api/endpoints.py#L194-L213

We deal with category list and if not know we say new but if none of that we return something without being defined in the first place, which creates the error message:

127.0.0.1 - - [10/Aug/2015 16:51:46] "GET /api/issues/search/foobar HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/karl/.virtualenvs/webcompatcom/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/karl/.virtualenvs/webcompatcom/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Users/karl/.virtualenvs/webcompatcom/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/karl/.virtualenvs/webcompatcom/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/karl/.virtualenvs/webcompatcom/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/karl/.virtualenvs/webcompatcom/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/karl/.virtualenvs/webcompatcom/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/karl/.virtualenvs/webcompatcom/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/karl/code/webcompat.com/webcompat/api/endpoints.py", line 213, in get_category_from_search
    return get_search_results(query_string, params)
UnboundLocalError: local variable 'query_string' referenced before assignment

ooops, my bad.

@karlcow
Copy link
Member Author

karlcow commented Aug 10, 2015

@karlcow
Copy link
Member Author

karlcow commented Aug 10, 2015

food for thoughts from http://blog.luisrei.com/articles/flaskrest.html

@app.errorhandler(404)
def not_found(error=None):
    message = {
            'status': 404,
            'message': 'Not Found: ' + request.url,
    }
    resp = jsonify(message)
    resp.status_code = 404

    return resp

@app.route('/users/<userid>', methods = ['GET'])
def api_users(userid):
    users = {'1':'john', '2':'steve', '3':'bill'}

    if userid in users:
        return jsonify({userid:users[userid]})
    else:
        return not_found()

@miketaylr
Copy link
Member

@karlcow the not_found solution looks good.

@karlcow
Copy link
Member Author

karlcow commented Aug 14, 2015

And my comment is on the wrong bug. 👊

karlcow added a commit to karlcow/webcompat.com that referenced this issue Aug 14, 2015
@karlcow
Copy link
Member Author

karlcow commented Aug 14, 2015

Once the #676 PR is merged, I will fix #667

@karlcow karlcow self-assigned this Aug 17, 2015
karlcow added a commit to karlcow/webcompat.com that referenced this issue Aug 18, 2015
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

2 participants