One of my packages (redcap
) is a service-specific wrapper around the venerable requests
. requests
exposes the HTTPError
exception that is raised e.g. when r.raise_for_status()
is called on a 400 response.
Since users of my package might want to catch HTTPError
s, what is the best way to design my API?
from redcap import Project, HTTPError
project = Project(foo, bar)
try:
project.some_bad_method()
except HTTPError:
do_something()
from redcap import Project
from requests import HTTPError
try:
project.some_bad_method()
except HTTPError:
do_something()
I lean towards 1 because it doesn't require my users to know about requests
. Any feedback is appreciated.
I think it's easiest to provide the
HTTPError
in your own module. It could certainly just returnrequests.HTTPError
if you want to maintain compatibility with whateverrequests
might do with that exception in the future. If your users get curious and look at the source, they might see that you're just passing it along and could then userequests.HTTPError
if they wish, right?