mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Update Handler.php
Improve API error handling
This commit is contained in:
parent
9ecff34cb4
commit
d9c031debb
@ -15,6 +15,7 @@ use Redirect;
|
|||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Utils;
|
use Utils;
|
||||||
|
use Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Handler.
|
* Class Handler.
|
||||||
@ -102,8 +103,18 @@ class Handler extends ExceptionHandler
|
|||||||
*/
|
*/
|
||||||
public function render($request, Exception $e)
|
public function render($request, Exception $e)
|
||||||
{
|
{
|
||||||
|
$value = Request::header('X-Ninja-Token');
|
||||||
|
|
||||||
if ($e instanceof ModelNotFoundException) {
|
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')) {
|
if (! class_exists('Utils')) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user