Skip to content

Conversation

@kshepherd
Copy link
Collaborator

This isn't intended as a proper solution for #46 but it's an example of what I'm suggesting initially as a better way to handle 500s (and I added 405s as they were easier for me to test)

Since the higher level "get this, search that" client methods don't put fetch_resource in a try block (typically that is done when trying to parse the actual JSON response), the new exception should be thrown all the way back to the calling script so it can be handled appropriately by end developers.

e.g.

# Forcing a 405 error to test (500 errors are handled too but are a bit harder to 'force' in a working system!)
try:
    r = d.fetch_resource(f"{d.API_ENDPOINT}/config/properties")
    print(r.status_code)
except DSpaceServerError as e:
    # Here you can see the formatted error message
    print("Here is a nice formatted error message:")
    print(e.format_message())
    # Here you can see a pretty print of the exception as dict, with the properties you can read
    print("\nHere is the exception as a dict:")
    pprint(e.__dict__)

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

Successfully merging this pull request may close these issues.

1 participant