kurttheviking / simple-hipchat-py

Python client fo HipChat's v1 API
Other
85 stars 25 forks source link

Hipchat fallback #14

Closed mwarkentin closed 9 years ago

mwarkentin commented 9 years ago

I've found myself wrapping calls to send messages to Hipchat with fallbacks (generally to email). This works fine, but I was wondering if it makes any sense to add some support for this to the library? The code generally looks something like this:

try:
    hipster.message_room(room_id=settings.HIPCHAT_ROOM_PRONETWORK, message_from=msg_from, message=msg, message_format='html', color=color, notify=True)
except URLError as e:
    body = u"Hipchat notification failed.\n{}\n\n".format(msg)
    if hasattr(e, 'reason'):
        body += u"Couldn't contact Hipchat:\n{}".format(e.reason)
    elif hasattr(e, 'code'):
        body += u"Hipchat error: {}".format(e.code)
        mail_managers(msg, body)
    except socket.timeout as e:
        body = u"Hipchat notification failed.\n{}\n\nSocket timeout.".format(msg)
        mail_managers(msg, body)
kurttheviking commented 9 years ago

@mwarkentin thanks for the suggestion; it's an interesting idea. In our company we do something similar (with various services) but the fallback sequence is encapsulated within an internal package, messenger.

In the interest of simplicity for this library I am inclined to leave the error treatments as is so others who have alternative fallback designs can handle the errors as they please. If this turns out to be a widely requested fallback I'll certainly re-evaluate that call.

mwarkentin commented 9 years ago

Makes sense. Thanks for taking a look!