I managed to do this using the following code. I enable 'debug' => true in my local configuration.
In app / start / global.php
App::error(function(Symfony\Component\HttpKernel\Exception\NotFoundHttpException $exception) { Log::error($exception); $response = Response::make(View::make('response') ->with('data', null) ->with('meta', 'Error, incorrect path') ->with('pagination', null)); $response->setStatusCode(404); $response->header('content-type', 'application/json', true); return $response; });
If any interest, the content of my submission
<?php echo json_encode(array( 'data' => $data, 'pagination' => $pagination, 'meta' => $meta), JSON_PRETTY_PRINT); ?>
The main problem was to use Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException as an exception type, not just NotFoundHttpException.
Using NotFoundHttpException, a 500 error was thrown.
kintso
source share