Kaynağa Gözat

Trap service errors and try another service.

tags/v0.1^2
Ben Kurtovic 12 yıl önce
ebeveyn
işleme
06d4a240f0
2 değiştirilmiş dosya ile 20 ekleme ve 8 silme
  1. +16
    -7
      earwigbot/exceptions.py
  2. +4
    -1
      earwigbot/wiki/site.py

+ 16
- 7
earwigbot/exceptions.py Dosyayı Görüntüle

@@ -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 <earwigbot.wiki.site.Site.delegate>`.
This is caught by :py:meth:`Site.delegate
<earwigbot.wiki.site.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 <earwigbot.wiki.site.Site.api_query>`.
"""

class SQLError(WikiToolsetError):
class SQLError(ServiceError):
"""Some error involving SQL querying occurred.

Raised by :py:meth:`Site.sql_query <earwigbot.wiki.site.Site.sql_query>`.
"""

class NoServiceError(WikiToolsetError):
"""No service is functioning to handle a specific task.

Raised by :py:meth:`Site.delegate <earwigbot.wiki.site.Site.delegate>`.
"""

class LoginError(WikiToolsetError):
"""An error occured while trying to login.



+ 4
- 1
earwigbot/wiki/site.py Dosyayı Görüntüle

@@ -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)

Yükleniyor…
İptal
Kaydet