Catch exceptions, raise Plug.Conn.WrapperError#278
Open
vincedevendra wants to merge 4 commits intoabsinthe-graphql:mainfrom
Open
Catch exceptions, raise Plug.Conn.WrapperError#278vincedevendra wants to merge 4 commits intoabsinthe-graphql:mainfrom
vincedevendra wants to merge 4 commits intoabsinthe-graphql:mainfrom
Conversation
Author
|
I should note that this likely only effects Phoenix applications without a router, since Phoenix Router wraps errors. As our application is solely a GraphQL server, we don't have/need a router. That's in line with the advice given here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We have a Phoenix application that expects the
[:phoenix, :endpoint, :stop]event to be executed, but I noticed that this was not happening when uncaught exceptions originated from this plug.This is because
Plug.Telemetryregisters this event by usingPlug.Conn.register_before_send, which, in turn, adds a key toconn.private.When there is an uncaught exception, Phoenix catches the error to render a standard error response here. When this sends the response, the telemetry callback is run and the event is executed.
Notice that if there is a
Plug.Conn.WrapperError, theconnfrom it is used, but if not,connis what's in scope at the time theRenderErrorsplug runs. This happens to be at the top of the middleware stack beforePlug.Telemetryregisters the callback. Thus, no[:phoenix, :endpoint, :stop]event is executed.Note also that bug reporting plugs may also expect request parsers etc. to have surfaced important bits of info on the
conn(we ran into this issue as well, but worked around it).This issue can be solved by rescuing errors in
calland usingPlug.Conn.Wrapper.reraise/4