REST and Exceptions, croaking and context loss in before hook
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start with lib/Dancer2/Core/App.pm around lines 1183 and 1185, then trace the before and before_error hook flow and the REST plugin's response-format handling. Reproduce an exception from a before hook and check whether the original exception and requested content type survive cleanup; done means the client receives the requested format with the relevant exception details.
Written by the indexing model from the issue text.
Description
Hello all,
We are trying to use Dancer2 to add a REST API to the Sympa software and we are facing a bit of an issue ... Actually 2 issues.
We use Throwable based exceptions everywhere we can.
Our idea is to use a "before" hook to do some stuff before every call, like analyzing some specific authentication headers and such.
If anything is "thrown" within our hook it is caught and turned into a string (croak in App.pm@1185), so when our "before_error" gets the error we don't have our "complex" exception anymore ... This is a bit of a problem as the original exceptions contain stuff that should be sent back to the client ... Any idea on how to have a Throwable bubble up to the Dancer Error ?
The other issue, we use the REST plugin to handle response formats, problem is, when an exception happens within a hook $app->cleanup runs (App.pm@1183) which trashes the request so the REST plugin loses it's content-type header and the response type then defaults to html, when the client expects (and requested) json ...
But maybe we are not doing things the right way, basically we need to have some code that runs before every route dispatching, code that may throw "complex" exceptions, and have those exceptions sent back to the client in the format it requested, any idea on how to acheive that ?
Thanks in advance
- Dominant language
- Perl
- Stars
- 604
- Forks
- 290
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 2
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PerlDancer/Dancer2
-
Add .gitattributes so share/skel keeps LF on a Windows git checkoutPossibly taken @sadhana-s-codez claimed this 8 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
PerlDancer/Dancer2#1854 · 1 comment ·
Maintainers usually reply within 2 days
-
dancer2 gen -c writes the Dockerfile outside the app directoryPossibly taken @sjh9714 claimed this 7 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
PerlDancer/Dancer2#1851 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
PerlDancer/Dancer2#1850 ·
Maintainers usually reply within 2 days
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
PerlDancer/Dancer2#1820 ·
Maintainers usually reply within 2 days
-
Enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
PerlDancer/Dancer2#1819 ·
Maintainers usually reply within 2 days
All issues in PerlDancer/Dancer2
Similar issues
-
observablt-ci
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
elastic/golang-crossbuild#840 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
LMS-Community/slimserver#1701 · 6 comments ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
RotherOSS/otobo#6286 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
fix(api): API v3 Product Read ignores request language (lc) for sample products and image URLsPossibly taken @muntasir-396 claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
openfoodfacts/openfoodfacts-server#15042 · 1 comment ·
Maintainers usually reply within 1 day