Raise specifically typed exceptions when a request fails #16
Labels
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
Is your feature request related to a problem? Please describe.
When a request to Dalle fails, the reason is logged but
None
is returned. This makes it difficult to programmatically figure out why the request failed and respond appropriately. For instance, if a request fails because the prompt violates safety standards, you may want to tell the user to try a different prompts. But if a request fails because of a lack of credits, you may want to tell the user to go add more credits before they try again.Describe the solution you'd like
I think it would be helpful for the Dalle2 client to raise exceptions when there are problems so code like the following would work
Describe alternatives you've considered
This would be a breaking change, so it should be considered carefully. Here are some alternatives that would preserve backwards compatibility:
Provide a context object
dalle2.error_status
that would provide information about the most recent request (similar to how Flask provides a request context object https://flask.palletsprojects.com/en/1.1.x/reqcontext/)But this is less clean and more error prone than exceptions.
Have exceptions be opt-in like
client = Dalle2('sess-XXXX', raise_on_error=True)
. But adding configuration overhead like this would make the package code more complex and also could cause a fair amount of friction for users.The text was updated successfully, but these errors were encountered: