summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-10-12 12:30:00 +0300
committerLars Wirzenius <liw@liw.fi>2017-10-12 12:30:00 +0300
commitb15e089854b5015ac01e41c41365df8cbbc98c00 (patch)
tree8da84412b7a824d9d0feee45a8a48f84da3724ac
parentc7bb0a2055edc6dcfcc6f1eb4ffa819955979960 (diff)
downloadqvisqve-b15e089854b5015ac01e41c41365df8cbbc98c00.tar.gz
Refactor: move API exceptions into their own module
-rw-r--r--qvarn/__init__.py10
-rw-r--r--qvarn/api_errors.py45
-rw-r--r--without-tests2
3 files changed, 56 insertions, 1 deletions
diff --git a/qvarn/__init__.py b/qvarn/__init__.py
index 6321b69..ceeb5f3 100644
--- a/qvarn/__init__.py
+++ b/qvarn/__init__.py
@@ -95,9 +95,17 @@ from .responses import (
unknown_search_field_response,
)
+from .api_errors import (
+ IdMismatch,
+ NoSuchResourceType,
+ NotJson,
+ TooManyResources,
+ TooManyResourceTypes,
+)
+
from .router import Router
from .file_router import FileRouter
from .version_router import VersionRouter
from .timestamp import get_current_timestamp
-from .api import QvarnAPI, NoSuchResourceType
+from .api import QvarnAPI
diff --git a/qvarn/api_errors.py b/qvarn/api_errors.py
new file mode 100644
index 0000000..368ddc5
--- /dev/null
+++ b/qvarn/api_errors.py
@@ -0,0 +1,45 @@
+# Copyright (C) 2017 Lars Wirzenius
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+class NoSuchResourceType(Exception): # pragma: no cover
+
+ def __init__(self, path):
+ super().__init__('No resource type for path {}'.format(path))
+
+
+class TooManyResourceTypes(Exception): # pragma: no cover
+
+ def __init__(self, path):
+ super().__init__('Too many resource types for path {}'.format(path))
+
+
+class TooManyResources(Exception): # pragma: no cover
+
+ def __init__(self, resource_id):
+ super().__init__('Too many resources with id {}'.format(resource_id))
+
+
+class NotJson(Exception): # pragma: no cover
+
+ def __init__(self, ct):
+ super().__init__('Was expecting application/json, not {}'.format(ct))
+
+
+class IdMismatch(Exception): # pragma: no cover
+
+ def __init__(self, obj_id, id_from_path):
+ super().__init__(
+ 'Resource has id {} but path says {}'.format(obj_id, id_from_path))
diff --git a/without-tests b/without-tests
index 636b24c..578e2d5 100644
--- a/without-tests
+++ b/without-tests
@@ -1,11 +1,13 @@
setup.py
qvarn/__init__.py
+qvarn/api_errors.py
qvarn/backend.py
qvarn/file_router.py
qvarn/logging.py
qvarn/responses.py
qvarn/router.py
qvarn/sql.py
+qvarn/subresource_router.py
qvarn/timestamp.py
qvarn/version.py
qvarn/version_router.py