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

Option to raise exceptions rather than print #5

Open
bleonard33 opened this issue Jun 6, 2023 · 0 comments
Open

Option to raise exceptions rather than print #5

bleonard33 opened this issue Jun 6, 2023 · 0 comments

Comments

@bleonard33
Copy link

When requesting a number of files (especially using the bulk download API endpoints), it is difficult to catch exceptions and errors that may arise when calling the API because they are caught and printed rather than raised to the user. It would be great to have the option to have exceptions passed on to handle them dynamically rather than caught and printed within the package.

For example, if a call times out or returns anything besides 200 in the middle of a number of requests, it's impossible to catch that with the current setup to handle and re-try the request because the package prints and moves on. Having the option to raise exceptions and non-200s as their own exceptions (and ideally exposing information about the URL being called during the issue to re-try or otherwise handle) would be ideal. Examples from BulkDownload.py where this could be addressed are below:

        if resp.status_code != 200:
            # This means something went wrong.
            jsonResult = resp.json()
            print('Error in calling API:', resp.url)
            print('Error code:', jsonResult['statusCode'])
            print('Error message:', jsonResult['message'])
    except requests.exceptions.Timeout:
        # Maybe set up for a retry, or continue in a retry loop
        print('Request failed due to timeout')
    except requests.exceptions.TooManyRedirects:
        # Tell the user their URL was bad and try a different one
        print('Request failed due to too many redirects')
    except requests.exceptions.RequestException as e:
        # catastrophic error. bail.
        raise SystemExit(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant