Skip to content

Commit

Permalink
normalize InvalidRequest api (#237)
Browse files Browse the repository at this point in the history
* normalize InvalidRequest api

* compose error message befare passing it to InvalidRequest
  • Loading branch information
mcucchi9 authored Nov 13, 2024
1 parent 7054d86 commit 79b5ef4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
13 changes: 1 addition & 12 deletions cads_adaptors/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from copy import deepcopy


class ParameterError(TypeError):
"""Raised when a request parameter is invalid."""


class InvalidRequest(Exception):
class InvalidRequest(ValueError):
"""Raised when an invalid request is sent to the adaptor."""

def __init__(self, msgs: None | str | list[str] = None):
if isinstance(msgs, str):
msgs = [msgs]

if msgs is not None:
super().__init__("\n".join(msgs))

self.messages = deepcopy(msgs)


class MarsRuntimeError(RuntimeError):
"""Raised when a MARS request fails."""
Expand Down
3 changes: 2 additions & 1 deletion cads_adaptors/validation/enforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def enforce(
for msg in [error_message(e) for e in errors]:
if msg not in msgs:
msgs.append(msg)
raise cads_adaptors.exceptions.InvalidRequest(msgs)
error_msg = "\n".join(msgs)
raise cads_adaptors.exceptions.InvalidRequest(error_msg)

return request

Expand Down

0 comments on commit 79b5ef4

Please sign in to comment.