Skip to content

Status code handler.#84

Closed
arteymix wants to merge 3 commits into0.2/redesigned-async-modelfrom
0.2/status-code-handler
Closed

Status code handler.#84
arteymix wants to merge 3 commits into0.2/redesigned-async-modelfrom
0.2/status-code-handler

Conversation

@arteymix
Copy link
Copy Markdown
Member

The status handler is invoked with perform_routing, so next can be used to jump
to the next status handler for a given status. If nothing matches, the router
handler is used.

The great thing about this implementation is that it reuses perform_routing and fallbacks on Router default handling if a status is not handled.

@arteymix arteymix self-assigned this May 28, 2015
@arteymix arteymix added this to the 0.2 milestone May 28, 2015
@arteymix
Copy link
Copy Markdown
Member Author

It requires some tests to cover the following cases:

  • status is registered
  • status is registered and handler invoke next (should trigger the next handler in queue)
  • status is not registered (fallbacks on Router default handling)

It might have to be rebased on 0.2/end-in-a-continuation it the latter get merged before.

@arteymix
Copy link
Copy Markdown
Member Author

We need a way to obtain the error message, probably through Request.params.

@arteymix arteymix force-pushed the 0.2/status-code-handler branch from 2c9586c to b2e9dc7 Compare May 28, 2015 12:18
@arteymix
Copy link
Copy Markdown
Member Author

Maybe it would be a good thing to set the status code before invoking the handler.

The default handling would only be for specific exceptions.

@arteymix
Copy link
Copy Markdown
Member Author

One important thing to document is the capability for status handler to change the thrown Error.

A status handler can turn a Redirection into a ClientError.NOT_FOUND, which could be useful to cancel the effect of a thrown status.

@arteymix arteymix force-pushed the 0.2/status-code-handler branch from f53722f to 48ffb12 Compare May 28, 2015 15:56
@arteymix
Copy link
Copy Markdown
Member Author

Setting the status code is not a good thing and will cause problems if another Error is thrown during the status handling.

Moreover, the response should be in the exact same state it was when the exception was thrown.

@arteymix arteymix force-pushed the 0.2/status-code-handler branch from 518e548 to bd45c61 Compare May 28, 2015 16:19
@arteymix
Copy link
Copy Markdown
Member Author

Using the request parameters can have the dangerous side-effect of overwritting existing keys in the parameters.

However, it does matter only if the original code or message value is desired during the status handling, which is not highly probable.

@arteymix arteymix force-pushed the 0.2/redesigned-async-model branch from 3f35fe8 to 1d68a33 Compare May 29, 2015 01:04
@arteymix arteymix force-pushed the 0.2/status-code-handler branch from fb0e287 to a301a6c Compare May 29, 2015 01:04
@arteymix arteymix force-pushed the 0.2/redesigned-async-model branch from 1d68a33 to 569be0d Compare May 30, 2015 02:48
@arteymix arteymix force-pushed the 0.2/status-code-handler branch from a301a6c to 05ceb04 Compare May 30, 2015 02:55
arteymix added 2 commits May 29, 2015 23:18
The status handler is invoked with perform_routing, so next can be used to jump
to the next status handler for a given status. If nothing matches, the router
handler is used.

Status handler must set the status code in the response as it remained in the
exact same state it was when the exception were thrown.

It also captures generated NOT_FOUND and METHOD_NOT_ALLOWED to provide a uniform
approach at handling status codes.
Keys 'code' and 'message' are setted in the request parameters so that the
status handler can access that information.

The request parameters are initialized if still null, which might happen if no
matcher has populated them.

Optimally, that information would go through a state, but this is not really
easy to do without making major modifications to the router.
@arteymix arteymix force-pushed the 0.2/status-code-handler branch from 05ceb04 to 0ba45dc Compare May 30, 2015 03:19
@arteymix arteymix force-pushed the 0.2/status-code-handler branch from 0ba45dc to f0f831f Compare May 30, 2015 03:24
@arteymix
Copy link
Copy Markdown
Member Author

Merged directly into master.

@arteymix arteymix closed this May 30, 2015
@arteymix arteymix deleted the 0.2/status-code-handler branch June 9, 2015 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant