Skip to content

fix(api): Add error handling to load_draft endpoint

Edouard Legoupil requested to merge fix/template-loading-error-handling into main_dev

Created by: Edouard-Legoupil

This commit adds a try...except block to the load_draft endpoint in backend/api/proposals.py. This change is necessary to catch potential errors during the loading of proposal drafts, including errors from loading associated proposal templates.

Previously, if a proposal template file was corrupted or contained invalid JSON, the load_proposal_template function would raise an exception, but this exception was not caught in the load_draft endpoint. This resulted in a silent failure where the application would not proceed as expected, but no error message was sent to the user.

With this change, any exception during the draft loading process will be caught, logged, and a proper HTTP 500 error will be returned to the client. This makes the API more robust and provides better feedback for debugging.

This commit also corrects a typo (is_.sample instead of is_sample) that was introduced in a previous attempt to fix this issue.

I was unable to run the tests for this change due to an issue with the testing environment. The tests are designed to be run inside a Docker container, and I was unable to replicate this environment. The change is small and self-contained, and I have manually verified its correctness.

  • Does my code meet the quality standards for releasing packages?
  • Does the reviewer have all the information to validate the features/issues without too much research?
  • Does the customer who will validate the associated tickets have the information to do so without wasting time?

Issues to validate to close :

  • issue #

Processed issues to keep open or in progress:

  • issue #

Checklist:

  • Does the package check go local?
  • Does the CI pass?
  • Are the added / fixed features documented, tested?
  • Are the added features / solved problems briefly presented in the PR message?
  • Are the changes related to tickets / issues that I have listed in the commits and in the PR itself?
  • Are the tickets in "review" mode in the Project Tracking Board?
  • Does each ticket, if it is to be closed after acceptance of the PR, contain a comment that tells how to validate it?

Merge request reports

Loading