PerlDancer / PerlDancer/Dancer2
REST and Exceptions, croaking and context loss in before hook
Nobody has claimed this yet.
- Dominant language
- Perl
- Stars
- 604
- Forks
- 288
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 5
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
Contributor 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.
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.
Assessment
- Tech stack
- perl
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100