Refactor error handling internally to follow RFC7807 (#362)

* Refactor error handling internally to follow RFC7807

* style fixes
This commit is contained in:
Nabeel S
2019-08-21 08:17:44 -04:00
committed by GitHub
parent 91a5eb535d
commit 182aabf426
25 changed files with 692 additions and 144 deletions

View File

@@ -57,7 +57,7 @@ class AcarsController extends Controller
protected function checkCancelled(Pirep $pirep)
{
if ($pirep->cancelled) {
throw new PirepCancelled();
throw new PirepCancelled($pirep);
}
}

View File

@@ -221,20 +221,20 @@ class PirepController extends Controller
/* @noinspection NotOptimalIfConditionsInspection */
if (setting('pilots.only_flights_from_current')
&& $user->curr_airport_id !== $pirep->dpt_airport_id) {
throw new UserNotAtAirport();
throw new UserNotAtAirport($user, $pirep->dpt_airport);
}
// See if this user is allowed to fly this aircraft
if (setting('pireps.restrict_aircraft_to_rank', false)
&& !$this->userSvc->aircraftAllowed($user, $pirep->aircraft_id)) {
throw new AircraftPermissionDenied();
throw new AircraftPermissionDenied($user, $pirep->aircraft);
}
// See if this aircraft is at the departure airport
/* @noinspection NotOptimalIfConditionsInspection */
if (setting('pireps.only_aircraft_at_dpt_airport')
&& $pirep->aircraft_id !== $pirep->dpt_airport_id) {
throw new AircraftNotAtAirport();
throw new AircraftNotAtAirport($pirep->aircraft);
}
// Find if there's a duplicate, if so, let's work on that
@@ -293,7 +293,7 @@ class PirepController extends Controller
) {
$can_use_ac = $this->userSvc->aircraftAllowed($user, $pirep->aircraft_id);
if (!$can_use_ac) {
throw new AircraftPermissionDenied();
throw new AircraftPermissionDenied($user, $pirep->aircraft);
}
}
@@ -335,7 +335,7 @@ class PirepController extends Controller
) {
$can_use_ac = $this->userSvc->aircraftAllowed($user, $pirep->aircraft_id);
if (!$can_use_ac) {
throw new AircraftPermissionDenied();
throw new AircraftPermissionDenied($user, $pirep->aircraft);
}
}

View File

@@ -98,7 +98,7 @@ class UserController extends Controller
* @param Request $request
*
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
* @throws \App\Exceptions\BidExists
* @throws \App\Exceptions\BidExistsForFlight
*
* @return mixed
*/