Whoops: Serve JSON errors when the Content-Type Request is application/json, rather than blindly rely only on HTTP_X_REQUESTED_WITH

This commit is contained in:
Djamil Legato
2016-02-01 16:38:58 -08:00
parent 3b8da60cf9
commit 2a4030e399

View File

@@ -15,6 +15,9 @@ class Errors
$grav = Grav::instance();
$config = $grav['config']->get('system.errors');
$headers = @apache_request_headers();
$jsonRequest = $headers['Accept'] == 'application/json';
// Setup Whoops-based error handler
$whoops = new \Whoops\Run;
@@ -31,11 +34,11 @@ class Errors
}
if (method_exists('Whoops\Util\Misc', 'isAjaxRequest')) { //Whoops 2.0
if (Whoops\Util\Misc::isAjaxRequest()) {
if (Whoops\Util\Misc::isAjaxRequest() || $jsonRequest) {
$whoops->pushHandler(new Whoops\Handler\JsonResponseHandler);
}
} elseif (function_exists('Whoops\isAjaxRequest')) { //Whoops 2.0.0-alpha
if (Whoops\isAjaxRequest()) {
if (Whoops\isAjaxRequest() || $jsonRequest) {
$whoops->pushHandler(new Whoops\Handler\JsonResponseHandler);
}
} else { //Whoops 1.x