From 90d2eae794505cc213099a00bd49289bb1935ea3 Mon Sep 17 00:00:00 2001 From: Jan Britz Date: Tue, 19 Nov 2024 11:00:58 +0100 Subject: [PATCH] refactor: remove `temporary` from constructor --- questionpy_server/web/_decorators.py | 11 ++++++----- questionpy_server/web/errors.py | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/questionpy_server/web/_decorators.py b/questionpy_server/web/_decorators.py index 53f8923..0f3da24 100644 --- a/questionpy_server/web/_decorators.py +++ b/questionpy_server/web/_decorators.py @@ -100,7 +100,7 @@ async def wrapper(request: web.Request, *args: _P.args, **kwargs: _P.kwargs) -> kwargs[param.name] = parts.question_state elif param.default is Parameter.empty: _msg = "A question state part is required but was not provided." - raise InvalidRequestError(reason=_msg, temporary=False) + raise InvalidRequestError(reason=_msg) return await handler(request, *args, **kwargs) @@ -132,7 +132,7 @@ async def wrapper(request: web.Request, *args: _P.args, **kwargs: _P.kwargs) -> if parts.main is None: _msg = "The main body is required but was not provided." - raise InvalidRequestError(reason=_msg, temporary=False) + raise InvalidRequestError(reason=_msg) kwargs[param.name] = _validate_from_http(parts.main, param.annotation) return await handler(request, *args, **kwargs) @@ -151,7 +151,7 @@ async def _get_package_from_request(request: web.Request) -> Package: f"The request URI specifies a package with hash '{uri_package_hash}', but the sent package has a hash of" f" '{parts.package.hash}'." ) - raise InvalidPackageError(reason=msg, temporary=False) + raise InvalidPackageError(reason=msg) package = None if uri_package_hash: @@ -171,7 +171,7 @@ async def _get_package_from_request(request: web.Request) -> Package: ) raise PackageNotFoundError(reason=msg, temporary=False) msg = "The package is required but was not provided." - raise InvalidRequestError(reason=msg, temporary=False) + raise InvalidRequestError(reason=msg) return package @@ -285,4 +285,5 @@ def _validate_from_http(raw_body: str | bytes, param_class: type[_M]) -> _M: try: return param_class.model_validate_json(raw_body) except ValidationError as error: - raise InvalidRequestError(reason="Invalid JSON body", temporary=False) from error + msg = "Invalid JSON body" + raise InvalidRequestError(reason=msg) from error diff --git a/questionpy_server/web/errors.py b/questionpy_server/web/errors.py index 8e38cae..d9a2d82 100644 --- a/questionpy_server/web/errors.py +++ b/questionpy_server/web/errors.py @@ -1,6 +1,8 @@ # This file is part of the QuestionPy Server. (https://questionpy.org) # The QuestionPy Server is free software released under terms of the MIT license. See LICENSE.md. # (c) Technische Universität Berlin, innoCampus +from typing import Any + from aiohttp import web from aiohttp.log import web_logger @@ -46,49 +48,49 @@ def __init__(self, *, reason: str | None, temporary: bool) -> None: class InvalidAttemptStateError(web.HTTPBadRequest, _ExceptionMixin): - def __init__(self, *, reason: str | None, temporary: bool) -> None: + def __init__(self, *, reason: str | None, **_: Any) -> None: super().__init__( "Invalid attempt state was provided", RequestError( error_code=RequestErrorCode.INVALID_ATTEMPT_STATE, reason=reason, - temporary=temporary, + temporary=False, ), ) class InvalidQuestionStateError(web.HTTPBadRequest, _ExceptionMixin): - def __init__(self, *, reason: str | None, temporary: bool) -> None: + def __init__(self, *, reason: str | None, **_: Any) -> None: super().__init__( "Invalid question state was provided", RequestError( error_code=RequestErrorCode.INVALID_QUESTION_STATE, reason=reason, - temporary=temporary, + temporary=False, ), ) class InvalidPackageError(web.HTTPBadRequest, _ExceptionMixin): - def __init__(self, *, reason: str | None, temporary: bool) -> None: + def __init__(self, *, reason: str | None, **_: Any) -> None: super().__init__( "Invalid package was provided", RequestError( error_code=RequestErrorCode.INVALID_PACKAGE, reason=reason, - temporary=temporary, + temporary=False, ), ) class InvalidRequestError(web.HTTPUnprocessableEntity, _ExceptionMixin): - def __init__(self, *, reason: str | None, temporary: bool) -> None: + def __init__(self, *, reason: str | None, **_: Any) -> None: super().__init__( "Invalid request body was provided", RequestError( error_code=RequestErrorCode.INVALID_REQUEST, reason=reason, - temporary=temporary, + temporary=False, ), )