Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST and Exceptions, croaking and context loss in before hook #1632

Open
yent opened this issue Oct 5, 2021 · 0 comments
Open

REST and Exceptions, croaking and context loss in before hook #1632

yent opened this issue Oct 5, 2021 · 0 comments

Comments

@yent
Copy link

yent commented Oct 5, 2021

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

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

No branches or pull requests

1 participant