Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

[BUG FIX] "500 OK" error responses #52

Merged
merged 1 commit into from
Mar 24, 2016
Merged

[BUG FIX] "500 OK" error responses #52

merged 1 commit into from
Mar 24, 2016

Conversation

michaelmoussa
Copy link
Contributor

This addresses the issue reported in #51.
#46 ensured that response reason phrases set by developers would be preserved when building error responses. Unfortunately, it also ensured that reason phrases NOT set by developers (i.e., "OK") would also be preserved.

This PR takes the following use cases into account. Let me know if I missed a possibility!

  1. All is well and an exception is thrown: Error response will have the status code corresponding to the code of the exception that was thrown (or 500 by default). Error response reason phrase will be whatever the HTTP standard is for the code that was chosen.
  2. Response is already in an error state, then an exception is thrown, which means either:
    1. The application caught an exception, updated the response, then threw the same exception. If that's the case, then we assume the reason phrase was also updated, and we keep it.
    2. The application encountered an error, updated the response, and then something else happened before getting to the FinalHandler (maybe another middleware in the error middleware pipeline does some kind of logging or external error reporting, and that failed). In this case, the reason phrase will be preserved if the resulting exception doesn't change the status code. If it does, then there will be a new reason phrase. I expect this should be a rare occurrence, but at least there is a sane default behavior when it happens.

If the current response already has a status code that corresponds to
the exception that was encountered, it is assumed the developer dealt
with the reason phrase as well, and the reason phrase will be preserved.
If not, the standard message for the resulting HTTP status code will be
used.
@weierophinney weierophinney added this to the 1.2.1 milestone Mar 24, 2016
@weierophinney weierophinney self-assigned this Mar 24, 2016
@weierophinney weierophinney merged commit e7d1b83 into zendframework:master Mar 24, 2016
weierophinney added a commit that referenced this pull request Mar 24, 2016
[BUG FIX] "500 OK" error responses
weierophinney added a commit that referenced this pull request Mar 24, 2016
weierophinney added a commit that referenced this pull request Mar 24, 2016
weierophinney added a commit that referenced this pull request Mar 24, 2016
@michaelmoussa michaelmoussa deleted the bugfix/51 branch March 24, 2016 23:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants