Coverage for portality / bll / exceptions.py: 96%
79 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-04 09:41 +0100
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-04 09:41 +0100
1import sys, traceback, json
3class AuthoriseException(Exception):
4 """
5 Exception to raise if an action is not authorised
6 ~~AuthNZ:Exception->AuthNZ:Feature~~
7 """
9 # standardised reasons why an action might not be allowed
10 NOT_OWNER = "not_owner"
11 WRONG_ROLE = "wrong_role"
12 WRONG_STATUS = "wrong_status"
13 NOT_AUTHORISED = "not_authorised"
15 def __init__(self, message=None, reason=None):
16 super(AuthoriseException, self).__init__(message)
17 self.reason = reason
19class NoSuchFormContext(Exception):
20 """
21 Exception to raise if a form context is requested that can't be found
22 """
23 pass
25class ArgumentException(Exception):
26 """
27 Exception to raise if an expected argument is not present
28 """
29 pass
31class SaveException(Exception):
32 """
33 Exception to raise if a save operation did not work as expected
34 """
35 pass
37class NoSuchObjectException(Exception):
38 """
39 Exception to raise if the object id given does not correspond to an actual object
40 in the datastore
41 """
42 pass
44class NoSuchPropertyException(Exception):
45 """
46 Exception to raise if an object does not have a property that was required of it
47 to complete the operation
48 """
49 pass
51class ConfigurationException(Exception):
52 """
53 Exception to raise when our own configuration is broken
54 """
55 pass
57class DuplicateArticleException(Exception):
58 """
59 Exception to raise when a duplicate article is detected, and this is not permitted
60 """
61 pass
63class ArticleNotAcceptable(Exception):
64 """
65 Exception to raise when an article does not have suitable data to be ingested into DOAJ
66 """
67 def __init__(self, *args, **kwargs):
68 self.message = kwargs.get("message", "")
69 self.result = kwargs.get("result", {})
70 super(ArticleNotAcceptable, self).__init__(*args)
72 def __str__(self):
73 super(ArticleNotAcceptable, self).__str__()
74 return self.message
76class ArticleMergeConflict(Exception):
77 """
78 Exception to raise when it's not clear which article to merge an update with
79 """
80 pass
82class ConcurrentUpdateRequestException(Exception):
83 """
84 Exception to raise when two update requests were submitted cuncurrently
85 """
86 pass
88class IllegalStatusException(Exception):
89 """
90 Exception to raise when an application is in a state that is not allowed for the current action
91 """
93 def __init__(self, message=None):
94 super(IllegalStatusException, self).__init__(message)
96class DuplicateUpdateRequest(Exception):
97 """
98 Exception to raise when an attempt is made to create mulitple or duplicate update requests for a journal
99 """
101 def __init__(self, message=None):
102 super(DuplicateUpdateRequest, self).__init__(message)
104class TooManyJournals(Exception):
105 """
106 Raised when too many journals in DOAJ and with the same issns is found
107 """
109 def __init__(self, message=None, context=None):
110 super(TooManyJournals, self).__init__(message)
113class IngestException(Exception):
114 """
115 ~~ArticleIngest:Exception->Article:Service~~
116 """
117 def __init__(self, *args, **kwargs):
118 self.stack = None
119 self.message = kwargs.get("message")
120 self.inner_message = kwargs.get("inner_message")
121 self.inner = kwargs.get("inner")
122 self.result = kwargs.get("result", {})
124 tb = sys.exc_info()[2]
125 if self.inner is not None:
126 if self.inner_message is None and self.inner.args[0] is not None:
127 self.inner_message = self.inner.args[0]
129 if tb is not None:
130 self.stack = "".join(traceback.format_exception(self.inner.__class__, self.inner, tb))
131 else:
132 self.stack = "".join(traceback.format_exception_only(self.inner.__class__, self.inner))
133 else:
134 if tb is not None:
135 self.stack = "".join(traceback.format_tb(tb))
136 else:
137 self.stack = "".join(traceback.format_stack())
139 def trace(self):
140 return self.stack
142 def __str__(self):
143 repr = "Ingest Exception: "
144 if self.message:
145 repr += self.message
146 if self.inner_message:
147 repr += " - " + self.inner_message
148 if self.result:
149 repr += " (" + json.dumps(self.result, cls=SetEncoder) + ")"
150 return repr
153class SetEncoder(json.JSONEncoder):
154 def default(self, obj):
155 if isinstance(obj, set):
156 return list(obj)
157 return json.JSONEncoder.default(self, obj)
159class RemoteServiceException(Exception):
160 """
161 Exception to raise when a remote service call fails
162 """
163 pass