This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
Catch exceptions thrown during rendering #2812
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fd03686
Catch render exceptions and trigger dispatch error
radnan 743a06c
Catch exception, cleanup, and re-throw when rendering model
257941f
Clear child models before injecting in case of error
4f1d1d3
clear out child models
682137e
Implemented clearChildren()
c89b5e1
Opening brace on same-line
radnan b98ca20
Trigger render_error event
radnan 5091be1
Added render.error event constant
radnan 2b5b708
Attach to render.error
radnan 50a5f39
Attach to 'render.error'
radnan 15e8718
Removed unnecessary cleanup
radnan File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ public function attach(Events $events) | |
{ | ||
$this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'injectViewModel'), -100); | ||
$this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'injectViewModel'), -100); | ||
$this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER_ERROR, array($this, 'injectViewModel'), -100); | ||
} | ||
|
||
/** | ||
|
@@ -83,6 +84,9 @@ public function injectViewModel(MvcEvent $e) | |
return; | ||
} | ||
|
||
if ($e->getError()) { | ||
$model->clearChildren(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should do this, or provide an alternate layout view model instead? |
||
$model->addChild($result); | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,13 @@ public function getChildren(); | |
*/ | ||
public function hasChildren(); | ||
|
||
/** | ||
* Clears out all child models | ||
* | ||
* @return ModelInterface | ||
*/ | ||
public function clearChildren(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a backwards incompatible break. We should add it as a separate interface, and then implement it in the concrete implementations we have; anything that requires its existence would check against it before operating on it. |
||
|
||
/** | ||
* Set the name of the variable to capture this model to, if it is a child model | ||
* | ||
|
This file contains 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
This file contains 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
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.
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.
I'm thinking we should do the same as we do with route and dispatch, and create a Zend\Mvc\RenderListener that encapsulates this. It'll be more consistent, allow swapping out internals more easily, and keep the functionality more readable.
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.
👍 with the RenderListener to keep consistency & readable.
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.
Actually, on investigating this, we already have a "RenderListener" -- it's the DefaultRenderingStrategy. What we need to do is treat this like we do dispatch and route: push the exception handling into these default listeners (I use the plural, as we have both Console and HTTP variants). I'm tackling this now.