Skip to content

feat(routers): move DiracHttpResponseError to routers layer#988

Open
mmascher wants to merge 7 commits into
DIRACGrid:mainfrom
mmascher:exceptions_review
Open

feat(routers): move DiracHttpResponseError to routers layer#988
mmascher wants to merge 7 commits into
DIRACGrid:mainfrom
mmascher:exceptions_review

Conversation

@mmascher

Copy link
Copy Markdown
  • move DiracHttpResponseError from core exceptions to diracx-routers
  • update imports in router factory and auth token router
  • keep app-level custom exception handling behavior unchanged
  • document error-boundary/fallback intent in coding conventions
  • normalize remaining e.args[0] usage to str(e) for consistency

* move DiracHttpResponseError from core exceptions to diracx-routers
* update imports in router factory and auth token router
* keep app-level custom exception handling behavior unchanged
* document error-boundary/fallback intent in coding conventions
* normalize remaining e.args[0] usage to str(e) for consistency
Copilot AI review requested due to automatic review settings July 10, 2026 17:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR moves DiracHttpResponseError out of diracx-core and into the diracx-routers layer to better reflect the HTTP boundary, while keeping the existing app-level exception-handling behavior intact. It also standardizes exception-to-string conversion in a few places and documents the intended error-handling boundaries in the developer conventions.

Changes:

  • Relocate DiracHttpResponseError into diracx-routers and update router/factory imports accordingly.
  • Normalize some e.args[0] usage to str(e) for safer, consistent error-string extraction.
  • Document error-handling boundaries and the intended “fallback vs explicit mapping” behavior in coding conventions.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
docs/dev/reference/coding-conventions.md Documents the intended exception boundary and fallback handler behavior, including when to use DiracHttpResponseError.
diracx-routers/src/diracx/routers/factory.py Updates imports and keeps the existing exception handler wiring; switches cached DB-unavailable reason extraction to str(e).
diracx-routers/src/diracx/routers/exceptions.py Introduces DiracHttpResponseError in the routers layer.
diracx-routers/src/diracx/routers/auth/token.py Updates the import location for DiracHttpResponseError used by the token endpoint’s OAuth-style error payload.
diracx-routers/src/diracx/routers/auth/device_flow.py Replaces e.args[0] with str(e) when translating exceptions to HTTP error details.
diracx-core/src/diracx/core/exceptions.py Removes DiracHttpResponseError from core exceptions and clarifies DiracError’s role as a fallback HTTP representation.
.gitignore Ignores a TIPS file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/dev/reference/coding-conventions.md Outdated
Comment thread diracx-routers/src/diracx/routers/exceptions.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@aldbr aldbr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks a lot for your PR!
The documentation looks reasonable. I just a few comments.

Note: the changes you made, or my suggestions, are breaking changes, because extensions could, in theory, already rely on these DiracHttpResponseError and DiracError.

In practice, only LHCb is running an extension in production as of now so it should be ok. We would just need to double check on our side + ask other VOs running diracx extensions in certification if they are already relying on the exceptions.

Comment thread .gitignore Outdated
Comment thread diracx-routers/src/diracx/routers/exceptions.py Outdated
Comment thread docs/dev/reference/coding-conventions.md Outdated
Comment thread diracx-core/src/diracx/core/exceptions.py Outdated
@DIRACGridBot DIRACGridBot marked this pull request as draft July 13, 2026 07:40
@mmascher

Copy link
Copy Markdown
Author

@aldbr I didn't realize moving DiracHttpResponseError could be a breaking change! I actually wanted to discuss this on Friday afternoon over Zoom, but as you know, my washing machine repair guy got in the way. 😄

Leaving it in exceptions.py and adding a comment saying it should only be used in routers (and only when HTTPException isn't sufficient) was the other option I considered. I'm happy to go back to that if you're OK with it.

Let's make sure my very first contribution is safe and doesn't break extensions or upset people. 😄

mmascher and others added 2 commits July 13, 2026 14:27
Remove local ignored file

Co-authored-by: aldbr <aldbr@outlook.com>
* return JSONResponse directly for authorization_pending
@aldbr aldbr linked an issue Jul 15, 2026 that may be closed by this pull request
@mmascher

Copy link
Copy Markdown
Author

@aldbr I think I am done here, I added commits as a reference and then solved the various threads.

@mmascher mmascher marked this pull request as ready for review July 15, 2026 15:12
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 diracx | 🛠️ Build #33602113 | 📁 Comparing c3e1303 against latest (19cb080)

  🔍 Preview build  

1 file changed
± dev/reference/coding-conventions/index.html

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DiracError, do we keep it?

3 participants