This repository was archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
Provide a dedicated service for server request error response generation #562
Merged
weierophinney
merged 5 commits into
zendframework:release-3.0.0
from
weierophinney:hotfix/use-constants-not-virtual-services
Feb 22, 2018
Merged
Provide a dedicated service for server request error response generation #562
weierophinney
merged 5 commits into
zendframework:release-3.0.0
from
weierophinney:hotfix/use-constants-not-virtual-services
Feb 22, 2018
Conversation
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
michalbundyra
approved these changes
Feb 22, 2018
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
I had a hope we can avoid using constants at all...
8acb272
to
ecbe016
Compare
@webimpress Please re-review; this removes the constant, and provides a dedicated service. |
public function __invoke(Throwable $e) | ||
{ | ||
$response = ($this->responseFactory)() | ||
->withStatus(Utils::getStatusCode($e, $response)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$response
is not yet defined so can't be used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch - and demonstrates I need to fully test this class. I'll push more commits momentarily.
7099eaf
to
85b832e
Compare
…erator Instead of re-using the existing `ErrorResponseGenerator`, this patch does the following: - Separates functionality for generating the error response into a trait, `Zend\Expressive\Response\ErrorResponseGeneratorTrait`. The method `prepareTemplatedResponse()` now expects the error, the response, and an array of data to provide to the template. - Updates `Zend\Expressive\Middleware\ErrorResponseGenerator` to use the new trait. - Creates a new class, `Zend\Expressive\Response\ServerRequestErrorResponseGenerator`, which expects a response factory, and optionally the debug flag, renderer, and template to render to. It composes the trait, and generates a response on-the-fly to pass to the trait methods. The `RequestHandlerRunnerFactory` has been updated to use this new service, and the `ServerRequestErrorResponseGeneratorFactory` was updated to generate an instance of the new class. These changes mean the constant SERVER_REQUEST_ERROR_RESPONSE_GENERATOR is no longer needed, and was thus removed.
Corrects an issue in the default message when a stack trace is produced as well.
Updates the methods of the `ErrorResponseGeneratorTrait` to accept the renderer and debug flag as arguments instead of relying on internal state; this ensures that they are of the type expected. Updated both implementations to pass the new arguments.
85b832e
to
457bc1f
Compare
weierophinney
added a commit
that referenced
this pull request
Feb 22, 2018
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Provide a dedicated service for the server request error response generator
Instead of re-using the existing
ErrorResponseGenerator
, this patch does the following:Zend\Expressive\Response\ErrorResponseGeneratorTrait
. The methodprepareTemplatedResponse()
now expects the error, the response, and an array of data to provide to the template.Zend\Expressive\Middleware\ErrorResponseGenerator
to use the new trait.Zend\Expressive\Response\ServerRequestErrorResponseGenerator
, which expects a response factory, and optionally the debug flag, renderer, and template to render to. It composes the trait, and generates a response on-the-fly to pass to the trait methods.The
RequestHandlerRunnerFactory
has been updated to use this new service, and theServerRequestErrorResponseGeneratorFactory
was updated to generate an instance of the new class.These changes mean the constant SERVER_REQUEST_ERROR_RESPONSE_GENERATOR is no longer needed, and was thus removed.