From 2a4030e399449444e31d6f2dd20032865ea96ffe Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Mon, 1 Feb 2016 16:38:58 -0800 Subject: [PATCH] Whoops: Serve JSON errors when the Content-Type Request is `application/json`, rather than blindly rely only on `HTTP_X_REQUESTED_WITH` --- system/src/Grav/Common/Errors/Errors.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Errors/Errors.php b/system/src/Grav/Common/Errors/Errors.php index f656e4a94..f07faa159 100644 --- a/system/src/Grav/Common/Errors/Errors.php +++ b/system/src/Grav/Common/Errors/Errors.php @@ -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