diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bc2c46794..cb06e79ebd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,7 +46,6 @@ and this project adheres to - Do not update OpenEdX enrollment if this one is already up-to-date on the remote lms -- ## [2.4.0] - 2024-06-21 diff --git a/src/backend/joanie/core/exceptions.py b/src/backend/joanie/core/exceptions.py index 80350014c6..3cc03e12c5 100644 --- a/src/backend/joanie/core/exceptions.py +++ b/src/backend/joanie/core/exceptions.py @@ -2,8 +2,6 @@ Specific exceptions for the core application """ -from requests.exceptions import ReadTimeout - class EnrollmentError(Exception): """An exception to raise if an enrollment fails.""" @@ -33,7 +31,7 @@ class CertificateGenerationError(Exception): """ -class BackendTimeOut(ReadTimeout): +class BackendTimeout(Exception): """ Exception raised when a backend reaches the timeout set when we are waiting for the response. diff --git a/src/backend/joanie/core/models/products.py b/src/backend/joanie/core/models/products.py index 05668d6fe1..4e79b25499 100644 --- a/src/backend/joanie/core/models/products.py +++ b/src/backend/joanie/core/models/products.py @@ -18,7 +18,7 @@ from urllib3.util import Retry from joanie.core import enums -from joanie.core.exceptions import BackendTimeOut, CertificateGenerationError +from joanie.core.exceptions import BackendTimeout, CertificateGenerationError from joanie.core.fields.schedule import OrderPaymentScheduleEncoder from joanie.core.flows.order import OrderFlow from joanie.core.models.accounts import User @@ -977,7 +977,7 @@ def submit_for_signature(self, user: User): backend_signature.delete_signing_procedure( contract.signature_backend_reference ) - except BackendTimeOut as exception: # pylint: disable=unused-variable + except BackendTimeout as exception: # pylint: disable=unused-variable handle_signature_deletion_error( order=self, error_message="Timeout on signature reference deletion" ) diff --git a/src/backend/joanie/core/utils/signature.py b/src/backend/joanie/core/utils/signature.py index e8469684b6..7179ee3ddf 100644 --- a/src/backend/joanie/core/utils/signature.py +++ b/src/backend/joanie/core/utils/signature.py @@ -40,8 +40,8 @@ def check_signature(request, settings_name): def handle_signature_deletion_error(order, error_message): """ - Handles the exception raised on the deleting of signing procedure. - It's responsible to reset the submission values from the outdated + Handles the exception raised on the deletion of a signing procedure. + It's responsible for resetting the submission values from the outdated contract of the order. """ logger.error( diff --git a/src/backend/joanie/signature/backends/lex_persona.py b/src/backend/joanie/signature/backends/lex_persona.py index 99051fc593..7e41b49ad3 100644 --- a/src/backend/joanie/signature/backends/lex_persona.py +++ b/src/backend/joanie/signature/backends/lex_persona.py @@ -9,9 +9,11 @@ from django.core.exceptions import ValidationError import requests +from requests.exceptions import ReadTimeout from rest_framework.request import Request from joanie.core import enums, models +from joanie.core.exceptions import BackendTimeout from joanie.core.utils.contract import order_has_organization_owner from joanie.signature import exceptions from joanie.signature.backends.base import BaseSignatureBackend @@ -522,7 +524,10 @@ def delete_signing_procedure(self, reference_id: str): url = f"{base_url}/api/workflows/{reference_id}" headers = {"Authorization": f"Bearer {token}"} - response = requests.delete(url, headers=headers, timeout=timeout) + try: + response = requests.delete(url, headers=headers, timeout=timeout) + except ReadTimeout as exception: + raise BackendTimeout("Deletion request is taking longer than expected.") from exception if not response.ok: logger.error( diff --git a/src/backend/joanie/tests/core/test_models_order.py b/src/backend/joanie/tests/core/test_models_order.py index 2e5dccd7d8..bd9ccc41b7 100644 --- a/src/backend/joanie/tests/core/test_models_order.py +++ b/src/backend/joanie/tests/core/test_models_order.py @@ -20,7 +20,7 @@ import responses from joanie.core import enums, factories -from joanie.core.exceptions import BackendTimeOut +from joanie.core.exceptions import BackendTimeout from joanie.core.models import Contract, CourseState from joanie.core.utils import contract_definition from joanie.payment.factories import BillingAddressDictFactory, InvoiceFactory @@ -1342,7 +1342,7 @@ def test_models_order_submit_for_signature_step_delete_signing_procedure_timeout responses.add( responses.DELETE, f"https://lex_persona.test01.com/api/workflows/{workflow_id}", - body=BackendTimeOut(), + body=BackendTimeout(), ) # Prepare the data for the new document to sign on the contract new_workflow_id = "wfl_id_fake_2"