1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Merge branch 'develop' of github.com:invoiceninja/invoiceninja into develop

This commit is contained in:
Hillel Coren 2016-11-06 13:45:09 +02:00
commit 31d5e28b69
2 changed files with 42 additions and 6 deletions

View File

@ -1,5 +1,7 @@
<?php namespace App\Exceptions;
use Braintree\Util;
use Illuminate\Support\Facades\Response;
use Redirect;
use Utils;
use Exception;
@ -69,7 +71,7 @@ class Handler extends ExceptionHandler
{
if ($e instanceof ModelNotFoundException) {
return Redirect::to('/');
} elseif ($e instanceof \Illuminate\Session\TokenMismatchException) {
} if ($e instanceof \Illuminate\Session\TokenMismatchException) {
// prevent loop since the page auto-submits
if ($request->path() != 'get_started') {
// https://gist.github.com/jrmadsen67/bd0f9ad0ef1ed6bb594e
@ -82,6 +84,40 @@ class Handler extends ExceptionHandler
}
}
if($this->isHttpException($e))
{
switch ($e->getStatusCode())
{
// not found
case 404:
if($request->header('X-Ninja-Token') != '') {
//API request which has hit a route which does not exist
$error['error'] = ['message'=>'Route does not exist'];
$error = json_encode($error, JSON_PRETTY_PRINT);
$headers = Utils::getApiHeaders();
return response()->make($error, 404, $headers);
}
break;
// internal error
case '500':
if($request->header('X-Ninja-Token') != '') {
//API request which produces 500 error
$error['error'] = ['message'=>'Internal Server Error'];
$error = json_encode($error, JSON_PRETTY_PRINT);
$headers = Utils::getApiHeaders();
return response()->make($error, 500, $headers);
}
break;
}
}
// In production, except for maintenance mode, we'll show a custom error screen
if (Utils::isNinjaProd()
&& !Utils::isDownForMaintenance()

View File

@ -36,11 +36,11 @@ class EntityRequest extends Request {
$class = Utils::getEntityClass($this->entityType);
if (method_exists($class, 'trashed')) {
$this->entity = $class::scope($publicId)->withTrashed()->firstOrFail();
} else {
$this->entity = $class::scope($publicId)->firstOrFail();
}
if (method_exists($class, 'trashed')) {
$this->entity = $class::scope($publicId)->withTrashed()->firstOrFail();
} else {
$this->entity = $class::scope($publicId)->firstOrFail();
}
return $this->entity;
}