Skip to content

Commit

Permalink
fixup! 🐛(backend) submit for signature handle timeout delete signing …
Browse files Browse the repository at this point in the history
…procedure
  • Loading branch information
jonathanreveille committed Sep 16, 2024
1 parent 3b7e733 commit 6d8744a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/backend/joanie/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CertificateGenerationError(Exception):
"""


class BackendTimeOut(ReadTimeout):
class BackendTimeout(ReadTimeout):
"""
Exception raised when a backend reaches the timeout set when we are waiting
for the response.
Expand Down
4 changes: 2 additions & 2 deletions src/backend/joanie/core/models/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
)
Expand Down
4 changes: 2 additions & 2 deletions src/backend/joanie/core/utils/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion src/backend/joanie/signature/backends/lex_persona.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 is processing...") from exception

if not response.ok:
logger.error(
Expand Down
4 changes: 2 additions & 2 deletions src/backend/joanie/tests/core/test_models_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 6d8744a

Please sign in to comment.