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

Provide a 404 when user passes a malformed library ID #89

Open
jonnybazookatone opened this issue Jan 15, 2016 · 2 comments
Open

Provide a 404 when user passes a malformed library ID #89

jonnybazookatone opened this issue Jan 15, 2016 · 2 comments

Comments

@jonnybazookatone
Copy link
Contributor

Currently, the API will return a 410 (which should be a 404 really) if someone passes a library ID that does not exist. However, if someone passes a malformed ID, such as 'foo', this will return a 500 as the ID conversion, of course, crashes. This should be handled, and return a 400.

@taylorshaulis
Copy link
Collaborator

I can confirm the 500 error when the library ID input is not valid.

We want status 404 if the input is valid but does not exist. We want status 400 if the input is invalid for example if it is 21 characters instead of 22.

For me https://api.adsabs.harvard.edu/v1/biblib/libraries/STjgfb_7QhSQOG511cvs1g returns 200 but https://api.adsabs.harvard.edu/v1/biblib/libraries/STjgfb_7QhSQOG511cvs1 returns 500. The problem was client side not server side so should be in the status 4XX range

@marblestation
Copy link
Contributor

This is the exception that is raised with bad library IDs:

INFO    29928 [10/13/2017 15:03:14]:    User gave pagination parameters:start: 0, rows: 100, sort: "bibcode asc", fl: "aff,author,pub,doi,title,pubdate,bibcode"
ERROR   29928 [10/13/2017 15:03:14]:    Exception on /libraries/NH0KuBgSU2KgrmgyisIYQ [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python2.7/dist-packages/flask_restful/__init__.py", line 477, in wrapper
    resp = resource(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/flask/views.py", line 84, in view
    return self.dispatch_request(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/flask_restful/__init__.py", line 587, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/app/biblib/views/library_view.py", line 362, in get
    library = self.helper_slug_to_uuid(library)
  File "/app/biblib/views/base_view.py", line 65, in helper_slug_to_uuid
    library_uuid = uuid.UUID(bytes=base64.urlsafe_b64decode(library_uuid))
  File "/usr/lib/python2.7/base64.py", line 119, in urlsafe_b64decode
    return b64decode(s.translate(_urlsafe_decode_translation))
  File "/usr/lib/python2.7/base64.py", line 78, in b64decode
    raise TypeError(msg)
TypeError: Incorrect padding

Library ID NH0KuBgSU2KgrmgyisIYQ in this example has 21 characters, a library created with my user is vlFg1sETQC-UlpkpGmiSnQ and has 22 characters.

Biblib base view adds two '==' to that string see, and then it uses base64.urlsafe_b64decode to decode. Since the example lacks 1 characters, we would need to append === instead of just == (total number characters should be multiple of 4).

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

3 participants