runtime
269 / 500
question 269 Inheritance & Composition · medium

A notifier that falls back

Order updates go out by email, and by SMS when email is down. Write Notifier(channels): it holds a list of channel objects in order of preference, each with send(message) that returns a receipt or raises ConnectionError. notify(message) tries the channels in order and returns the first receipt; every failure it skipped is kept in failures as "<channel class name>: <error message>". If every channel fails, raise DeliveryFailed (your own exception) with all the failures in its message.

ClassNotifier(channels) with attributes channels and failures (the failures of the latest notify)
`notify(message)`returns the first receipt; resets failures at the start of each call
RaisesDeliveryFailed (a subclass of Exception) when no channel succeeds; other errors are not caught

Loading your progress…

A notifier that falls back — Python practice · Runtime