1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Update Handler.php

Improve API error handling
This commit is contained in:
David Bomba 2018-09-20 21:39:45 +10:00 committed by GitHub
parent 9ecff34cb4
commit d9c031debb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,6 +15,7 @@ use Redirect;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Utils;
use Request;
/**
* Class Handler.
@ -102,8 +103,18 @@ class Handler extends ExceptionHandler
*/
public function render($request, Exception $e)
{
$value = Request::header('X-Ninja-Token');
if ($e instanceof ModelNotFoundException) {
return Redirect::to('/');
if( isset($value) && strlen($value) > 1 ){
$headers = \App\Libraries\Utils::getApiHeaders();
$response = json_encode(['message' => 'record does not exist'], JSON_PRETTY_PRINT);
return Response::make($response, 404, $headers);
}
else
return Redirect::to('/');
}
if (! class_exists('Utils')) {