diff --git a/earwigbot/exceptions.py b/earwigbot/exceptions.py index 193c9ed..f321ab7 100644 --- a/earwigbot/exceptions.py +++ b/earwigbot/exceptions.py @@ -31,9 +31,10 @@ This module contains all exceptions used by EarwigBot:: | +-- BrokenSocketError +-- WikiToolsetError +-- SiteNotFoundError + +-- ServiceError + | +-- APIError + | +-- SQLError +-- NoServiceError - +-- APIError - +-- SQLError +-- LoginError +-- NamespaceNotFoundError +-- PageNotFoundError @@ -82,13 +83,15 @@ class SiteNotFoundError(WikiToolsetError): Raised by :py:class:`~earwigbot.wiki.sitesdb.SitesDB`. """ -class NoServiceError(WikiToolsetError): - """No service is functioning to handle a specific task. +class ServiceError(WikiToolsetError): + """Base exception class for an error within a service (the API or SQL). - Raised by :py:meth:`Site.delegate `. + This is caught by :py:meth:`Site.delegate + ` to indicate a service is + non-functional so another, less-preferred one can be tried. """ -class APIError(WikiToolsetError): +class APIError(ServiceError): """Couldn't connect to a site's API. Perhaps the server doesn't exist, our URL is wrong or incomplete, or @@ -97,12 +100,18 @@ class APIError(WikiToolsetError): Raised by :py:meth:`Site.api_query `. """ -class SQLError(WikiToolsetError): +class SQLError(ServiceError): """Some error involving SQL querying occurred. Raised by :py:meth:`Site.sql_query `. """ +class NoServiceError(WikiToolsetError): + """No service is functioning to handle a specific task. + + Raised by :py:meth:`Site.delegate `. + """ + class LoginError(WikiToolsetError): """An error occured while trying to login. diff --git a/earwigbot/wiki/site.py b/earwigbot/wiki/site.py index a95f7cc..6c8312e 100644 --- a/earwigbot/wiki/site.py +++ b/earwigbot/wiki/site.py @@ -837,5 +837,8 @@ class Site(object): order = self._get_service_order() for srv in order: if srv in services: - return services[srv](*args, **kwargs) + try: + return services[srv](*args, **kwargs) + except exceptions.ServiceError: + continue raise exceptions.NoServiceError(services)