浏览代码

Trap service errors and try another service.

tags/v0.1^2
Ben Kurtovic 12 年前
父节点
当前提交
06d4a240f0
共有 2 个文件被更改,包括 20 次插入8 次删除
  1. +16
    -7
      earwigbot/exceptions.py
  2. +4
    -1
      earwigbot/wiki/site.py

+ 16
- 7
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 <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 查看文件

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

正在加载...
取消
保存