Skip to content
Permalink
Browse files

Also adjust ErrorMiddleware to be PHP7 throwable aware.

  • Loading branch information...
dereuromark committed Nov 25, 2017
1 parent 4ee5db4 commit 39e41d019e5577b5dda50e4fdda3203debb6a88a
Showing with 26 additions and 9 deletions.
  1. +26 −9 src/Error/Middleware/ErrorHandlerMiddleware.php
@@ -21,6 +21,7 @@
use Cake\Error\ExceptionRenderer;
use Cake\Log\Log;
use Exception;
use Throwable;
/**
* Error handling middleware.
@@ -93,8 +94,10 @@ public function __invoke($request, $response, $next)
{
try {
return $next($request, $response);
} catch (Exception $e) {
return $this->handleException($e, $request, $response);
} catch (Throwable $exception) {
return $this->handleException($exception, $request, $response);
} catch (Exception $exception) {
return $this->handleException($exception, $request, $response);
}
}
@@ -114,18 +117,32 @@ public function handleException($exception, $request, $response)
$this->logException($request, $exception);
return $res;
} catch (Exception $e) {
$this->logException($request, $e);
$body = $response->getBody();
$body->write('An Internal Server Error Occurred');
$response = $response->withStatus(500)
->withBody($body);
} catch (Throwable $exception) {
$this->logException($request, $exception);
$response = $this->handleInternalError($response);
} catch (Exception $exception) {
$this->logException($request, $exception);
$response = $this->handleInternalError($response);
}
return $response;
}
/**
* @param \Psr\Http\Message\ResponseInterface $response The response
*
* @return \Psr\Http\Message\ResponseInterface A response
*/
protected function handleInternalError($response)
{
$body = $response->getBody();
$body->write('An Internal Server Error Occurred');
$response = $response->withStatus(500)
->withBody($body);
return $response;
}
/**
* Get a renderer instance
*

0 comments on commit 39e41d0

Please sign in to comment.
You can’t perform that action at this time.