Is the following in poor taste?
This would be contained within a groupme
module. Does it make sense to re-define a RequestException
class within this module? If I didn't, wouldn't consumers of the module need to be aware of the underlying requests.exceptions.RequestException
being thrown:
...
class Bot(object):
API_BASE_URL = 'http://api.groupme.com/v3/bots/{route}'
API_POST_URL = API_BASE_URL.format(route='post')
def __init__(self, bot_id):
self.bot_id = bot_id
def post(self, message):
try:
data = {'bot_id': self.bot_id, 'message': message}
response = requests.post(Bot.API_POST_URL, data)
response.raise_for_status()
except requests.exceptions.RequestException as ex:
raise RequestException('Failed to post bot message') from ex
class RequestException(Exception):
...
And the groupme
module / above code would then be used in the following manner:
import groupme
bot = groupme.Bot('abcdef123')
try:
bot.post('Hello, world!')
except groupme.RequestException as ex: # this seems cleaner as opposed to requests.exceptions.RequestException
print(ex)