Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Handle PHP 7 Throwable in ApiProblemListener.
  • Loading branch information
MichaelGooden committed Nov 10, 2016
commit fe79ffe00b794e5fa4565fdc110c44aa56b7a5b5
6 changes: 4 additions & 2 deletions src/Listener/ApiProblemListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace ZF\ApiProblem\Listener;

use Exception;
use Throwable;
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\AbstractListenerAggregate;
use Zend\Http\Header\Accept as AcceptHeader;
Expand Down Expand Up @@ -96,7 +98,7 @@ public function onRender(MvcEvent $e)
$status = $e->getResponse()->getStatusCode();
$exception = $model->getVariable('exception');

if ($exception instanceof \Exception) {
if ($exception instanceof Throwable || $exception instanceof Exception) {
$apiProblem = new ApiProblem($status, $exception);
} else {
$apiProblem = new ApiProblem($status, $model->getVariable('message'));
Expand Down Expand Up @@ -156,7 +158,7 @@ public function onDispatchError(MvcEvent $e)

// Marshall an ApiProblem and view model based on the exception
$exception = $e->getParam('exception');
if (! $exception instanceof \Exception) {
if (! ($exception instanceof Throwable || $exception instanceof Exception)) {
// If it's not an exception, do not know what to do.
return;
}
Expand Down