Created
October 23, 2014 10:30
-
-
Save alnutile/96eba152605a321034de to your computer and use it in GitHub Desktop.
Response with json on 500 errors file app/Http/Kernel.php
This file contains hidden or 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
| <?php namespace BehatEditor\Http; | |
| use BehatEditor\Services\ResponseServices; | |
| use Exception; | |
| use Illuminate\Foundation\Http\Kernel as HttpKernel; | |
| use Illuminate\Support\Facades\Log; | |
| use Illuminate\Support\Facades\Response; | |
| class Kernel extends HttpKernel { | |
| /** | |
| * The application's HTTP middleware stack. | |
| * | |
| * @var array | |
| */ | |
| protected $middleware = [ | |
| 'BehatEditor\Http\Middleware\UnderMaintenance', | |
| 'Illuminate\Cookie\Middleware\EncryptCookies', | |
| 'Illuminate\Cookie\Middleware\AddQueuedCookiesToRequest', | |
| 'Illuminate\Session\Middleware\ReadSession', | |
| 'Illuminate\Session\Middleware\WriteSession', | |
| 'Illuminate\View\Middleware\ShareErrorsFromSession', | |
| 'BehatEditor\Http\Middleware\CsrfTokenIsValid', | |
| ]; | |
| /** | |
| * @var \BehatEditor\Services\ResponseServices | |
| */ | |
| protected $responseServices; | |
| /** | |
| * Handle an incoming HTTP request. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function handle($request) | |
| { | |
| try | |
| { | |
| return parent::handle($request); | |
| } | |
| catch (Exception $e) | |
| { | |
| if($request->wantsJson()) { | |
| Log::error($e->getMessage()); | |
| return Response::json($this->getResponseService()->respond($e->getMessage(), sprintf("Request Failed %s", $e->getMessage())), 500); | |
| } | |
| throw $e; | |
| } | |
| } | |
| public function getResponseService() | |
| { | |
| if($this->responseServices == null) | |
| { | |
| $this->setRepsonseService(); | |
| } | |
| return $this->responseServices; | |
| } | |
| public function setRepsonseService($responseServices = false) | |
| { | |
| if($responseServices == false) | |
| { | |
| $this->responseServices = new ResponseServices(); | |
| } | |
| return $this; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment