Fixes (#435)
* Add flight level field to PIREP field closes #401 * Default value for distance 0 closes #400 * Block airline deletion if assets exist #367 * Formatting * Move some of the base exception classes * Fix skin references to use settings table * Set default for theme name if setting is wrong
This commit is contained in:
@@ -3,8 +3,12 @@
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException as SymfonyHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||
|
||||
abstract class HttpException extends SymfonyHttpException
|
||||
/**
|
||||
* Abstract class for an exception which needs to satisty the RFC 78707 interface
|
||||
*/
|
||||
abstract class AbstractHttpException extends SymfonyHttpException implements HttpExceptionInterface
|
||||
{
|
||||
/**
|
||||
* Return the RFC 7807 error type (without the URL root)
|
||||
@@ -45,7 +49,7 @@ abstract class HttpException extends SymfonyHttpException
|
||||
/**
|
||||
* Return a response object that can be used by Laravel
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
@@ -53,11 +57,6 @@ abstract class HttpException extends SymfonyHttpException
|
||||
$headers['content-type'] = 'application/problem+json';
|
||||
$headers = array_merge($headers, $this->getHeaders());
|
||||
|
||||
return response()
|
||||
->json(
|
||||
$this->getJson(),
|
||||
$this->getStatusCode(),
|
||||
$headers
|
||||
);
|
||||
return response()->json($this->getJson(), $this->getStatusCode(), $headers);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ use App\Models\Aircraft;
|
||||
/**
|
||||
* Class AircraftNotAtAirport
|
||||
*/
|
||||
class AircraftNotAtAirport extends HttpException
|
||||
class AircraftNotAtAirport extends AbstractHttpException
|
||||
{
|
||||
public const MESSAGE = 'The aircraft is not at the departure airport';
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace App\Exceptions;
|
||||
use App\Models\Aircraft;
|
||||
use App\Models\User;
|
||||
|
||||
class AircraftPermissionDenied extends HttpException
|
||||
class AircraftPermissionDenied extends AbstractHttpException
|
||||
{
|
||||
public const MESSAGE = 'User is not allowed to fly this aircraft';
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
class AirportNotFound extends HttpException
|
||||
class AirportNotFound extends AbstractHttpException
|
||||
{
|
||||
private $icao;
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions\Converters;
|
||||
namespace App\Exceptions;
|
||||
|
||||
use App\Exceptions\HttpException;
|
||||
use Exception;
|
||||
|
||||
class NotFound extends HttpException
|
||||
class AssetNotFound extends AbstractHttpException
|
||||
{
|
||||
private $exception;
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Exceptions;
|
||||
|
||||
use App\Models\Flight;
|
||||
|
||||
class BidExistsForFlight extends HttpException
|
||||
class BidExistsForFlight extends AbstractHttpException
|
||||
{
|
||||
private $flight;
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Exceptions\Converters;
|
||||
|
||||
use App\Exceptions\HttpException;
|
||||
use App\Exceptions\AbstractHttpException;
|
||||
use Exception;
|
||||
|
||||
class GenericException extends HttpException
|
||||
class GenericExceptionAbstract extends AbstractHttpException
|
||||
{
|
||||
private $exception;
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Exceptions\Converters;
|
||||
|
||||
use App\Exceptions\HttpException;
|
||||
use App\Exceptions\AbstractHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException as SymfonyHttpException;
|
||||
|
||||
class SymfonyException extends HttpException
|
||||
class SymfonyException extends AbstractHttpException
|
||||
{
|
||||
private $exception;
|
||||
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
namespace App\Exceptions\Converters;
|
||||
|
||||
use App\Exceptions\HttpException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Exceptions\AbstractHttpException;
|
||||
use Illuminate\Validation\ValidationException as IlluminateValidationException;
|
||||
|
||||
class ValidationException extends HttpException
|
||||
class ValidationException extends AbstractHttpException
|
||||
{
|
||||
private $validationException;
|
||||
private $errorDetail;
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Exceptions;
|
||||
|
||||
use App\Models\Flight;
|
||||
|
||||
class DuplicateFlight extends HttpException
|
||||
class DuplicateFlight extends AbstractHttpException
|
||||
{
|
||||
private $flight;
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use App\Exceptions\Converters\GenericException;
|
||||
use App\Exceptions\Converters\NotFound;
|
||||
use App\Exceptions\Converters\GenericExceptionAbstract;
|
||||
use App\Exceptions\Converters\SymfonyException;
|
||||
use App\Exceptions\Converters\ValidationException;
|
||||
use Exception;
|
||||
@@ -33,7 +32,7 @@ class Handler extends ExceptionHandler
|
||||
protected $dontReport = [
|
||||
AuthenticationException::class,
|
||||
AuthorizationException::class,
|
||||
HttpException::class,
|
||||
AbstractHttpException::class,
|
||||
IlluminateValidationException::class,
|
||||
ModelNotFoundException::class,
|
||||
SymfonyHttpException::class,
|
||||
@@ -53,7 +52,7 @@ class Handler extends ExceptionHandler
|
||||
if ($request->is('api/*')) {
|
||||
Log::error('API Error', $exception->getTrace());
|
||||
|
||||
if ($exception instanceof HttpException) {
|
||||
if ($exception instanceof AbstractHttpException) {
|
||||
return $exception->getResponse();
|
||||
}
|
||||
|
||||
@@ -63,7 +62,7 @@ class Handler extends ExceptionHandler
|
||||
|
||||
if ($exception instanceof ModelNotFoundException ||
|
||||
$exception instanceof NotFoundHttpException) {
|
||||
$error = new NotFound($exception);
|
||||
$error = new AssetNotFound($exception);
|
||||
return $error->getResponse();
|
||||
}
|
||||
|
||||
@@ -79,11 +78,11 @@ class Handler extends ExceptionHandler
|
||||
return $error->getResponse();
|
||||
}
|
||||
|
||||
$error = new GenericException($exception);
|
||||
$error = new GenericExceptionAbstract($exception);
|
||||
return $error->getResponse();
|
||||
}
|
||||
|
||||
if ($exception instanceof HttpException
|
||||
if ($exception instanceof AbstractHttpException
|
||||
&& $exception->getStatusCode() === 403) {
|
||||
return redirect()->guest('login');
|
||||
}
|
||||
@@ -112,24 +111,25 @@ class Handler extends ExceptionHandler
|
||||
/**
|
||||
* Render the given HttpException.
|
||||
*
|
||||
* @param HttpException $e
|
||||
* @param AbstractHttpException $e
|
||||
*
|
||||
* @return \Illuminate\Http\Response|Response
|
||||
*/
|
||||
protected function renderHttpException(HttpExceptionInterface $e)
|
||||
{
|
||||
Flash::error($e->getMessage());
|
||||
|
||||
$status = $e->getStatusCode();
|
||||
view()->replaceNamespace('errors', [
|
||||
resource_path('views/layouts/'.config('phpvms.skin').'/errors'),
|
||||
resource_path('views/layouts/'.setting('general.theme', 'default').'/errors'),
|
||||
resource_path('views/errors'),
|
||||
__DIR__.'/views',
|
||||
]);
|
||||
|
||||
if (view()->exists("errors::{$status}")) {
|
||||
//if (view()->exists('layouts' . config('phpvms.skin') .'.errors.' .$status)) {
|
||||
return response()->view("errors::{$status}", [
|
||||
'exception' => $e,
|
||||
'SKIN_NAME' => config('phpvms.skin'),
|
||||
'SKIN_NAME' => setting('general.theme', 'default'),
|
||||
], $status, $e->getHeaders());
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Exceptions;
|
||||
|
||||
use App\Models\Pirep;
|
||||
|
||||
class PirepCancelNotAllowed extends HttpException
|
||||
class PirepCancelNotAllowed extends AbstractHttpException
|
||||
{
|
||||
private $pirep;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Exceptions;
|
||||
|
||||
use App\Models\Pirep;
|
||||
|
||||
class PirepCancelled extends HttpException
|
||||
class PirepCancelled extends AbstractHttpException
|
||||
{
|
||||
private $pirep;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
class Unauthenticated extends HttpException
|
||||
class Unauthenticated extends AbstractHttpException
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Exceptions;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class UserBidLimit extends HttpException
|
||||
class UserBidLimit extends AbstractHttpException
|
||||
{
|
||||
private $user;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace App\Exceptions;
|
||||
use App\Models\Airport;
|
||||
use App\Models\User;
|
||||
|
||||
class UserNotAtAirport extends HttpException
|
||||
class UserNotAtAirport extends AbstractHttpException
|
||||
{
|
||||
public const MESSAGE = 'Pilot is not at the departure airport';
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Exceptions;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class UserPilotIdExists extends HttpException
|
||||
class UserPilotIdExists extends AbstractHttpException
|
||||
{
|
||||
public const MESSAGE = 'A user with this pilot ID already exists';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user