Skip to content

Conversation

@Marc-Andrieu
Copy link
Member

@Marc-Andrieu Marc-Andrieu commented Sep 29, 2025

Description

Related Issues

Supersedes these two PRs:

Changes Made

  • Rewrite of the PaymentTool.init_checkout() method to handle at once all the known possible exceptions, with cleaner separation in paragraphs and a bit less nesting (no more try in a try in a try).
  • Specific (yet factorized!) error logs, that are short and informative
  • New PayerUser payment schema to easily pass the 4 desired pieces of information
  • Catching exceptions in endpoints that use init_checkout

Also fixes the bug introduced in the last release that makes it impossible to retry when it failed due to issues in the payer user's infomation.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 🔨 Refactor (non-breaking change that neither fixes a bug nor adds a feature)
  • 🔧 Infra CI/CD (changes to configs of workflows)
  • 💥 BREAKING CHANGE (fix or feature that require a new minimal version of the front-end)

Impact & Scope

  • Core functionality changes
  • Single module changes
  • Multiple modules changes
  • Database migrations required
  • Other

Testing

  • Added/modified tests that pass the CI
  • Tested in a pre-prod
  • Tested this locally

Documentation

  • Updated docs accordingly (docs.myecl.fr) :
  • Code includes docstrings
  • No documentation needed
  • Inline comments

@codecov
Copy link

codecov bot commented Sep 29, 2025

Codecov Report

❌ Patch coverage is 70.58824% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.41%. Comparing base (d029157) to head (81bffed).

Files with missing lines Patch % Lines
app/core/payment/payment_tool.py 77.27% 5 Missing ⚠️
app/modules/raid/endpoints_raid.py 33.33% 4 Missing ⚠️
app/core/myeclpay/endpoints_myeclpay.py 66.66% 2 Missing ⚠️
app/modules/cdr/endpoints_cdr.py 66.66% 2 Missing ⚠️
...s/sport_competition/endpoints_sport_competition.py 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #861      +/-   ##
==========================================
- Coverage   85.46%   85.41%   -0.05%     
==========================================
  Files         187      187              
  Lines       14320    14335      +15     
==========================================
+ Hits        12238    12244       +6     
- Misses       2082     2091       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Marc-Andrieu Marc-Andrieu marked this pull request as ready for review September 29, 2025 19:05
db=db,
)
except Exception:
raise HTTPException(status_code=502, detail="Cannot init the checkout")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, 502 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you try/except this block?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 5xx to indicate the client that it is not a client-side error (it's on HelloAsso's side at best or Hyperion's side at worst)
  • Try-except because
    • init_checkout may result in an exception
    • we need to raise a HTTPException to return something gracefully (currently the client has no idea what happens when initiating a checkout still fails)

hyperion_error_logger.error(
f"Payment: failed to init a checkout with HA for module {module} and name {checkout_name}. No checkout id returned",
except BadRequestException:
# In this case only, we retry
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the comment explaining why we retry without payer infos?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted, it's more explicative with this line + the previous comment

f"{exception_start}: unauthorized for headers {e.headers}.",
)
raise
except BadRequestException as e:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we have multiple try/except chained, it's kind of strange. You catch a BadRequestException then raise it then catch it a second time only to log it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should go in the previous except block

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple try/except chained

Well, now we have 2 instead of 3

You catch a BadRequestException then raise it then catch it a second time only to log it.

What is wrong with this? We catch it if it happens with payer info, in the case we retry without, and if it happens again, we log it cleanly.

I think this should go in the previous except block

I tried to have all the logging part put together at the end of the method instead of spread out across the method, so that the code be more readable. Perhaps it's not good practice, what do you think?

f"{exception_start}: bad request for reason {e.data or e.body}.",
)
raise
except MissingHelloAssoCheckoutIdError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem. If the purpose is to log this, I think it would be simpler to do it directly

db=db,
)
except Exception:
raise HTTPException(status_code=502, detail="Cannot init the checkout")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you return a 502?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants