From d3d464e179ae28985e476a57aac2a86d6144dc91 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 12 Apr 2023 04:36:05 -0700 Subject: [PATCH] Improved commenting Signed-off-by: snipe --- app/Exceptions/Handler.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 187802521..e1145cd5c 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -72,27 +72,31 @@ class Handler extends ExceptionHandler return response()->json(Helper::formatStandardApiResponse('error', null, 'Invalid JSON'), 422); } + // Handle SCIM exceptions if ($e instanceof SCIMException) { return response()->json(Helper::formatStandardApiResponse('error', null, 'Invalid SCIM Request'), 400); } + // Handle standard requests that fail because Carbon cannot parse the date on validation (when a submitted date value is definitely not a date) if ($e instanceof InvalidFormatException) { return redirect()->back()->with('error', trans('validation.date', ['attribute' => 'date'])); } - // Handle Ajax requests that fail because the model doesn't exist + // Handle API requests that fail if ($request->ajax() || $request->wantsJson()) { + // Handle API requests that fail because Carbon cannot parse the date on validation (when a submitted date value is definitely not a date) if ($e instanceof InvalidFormatException) { - return response()->json(Helper::formatStandardApiResponse('error', null, trans('validation.date')), 200); + return response()->json(Helper::formatStandardApiResponse('error', null, trans('validation.date', ['attribute' => 'date'])), 200); } - + // Handle API requests that fail because the model doesn't exist if ($e instanceof \Illuminate\Database\Eloquent\ModelNotFoundException) { $className = last(explode('\\', $e->getModel())); return response()->json(Helper::formatStandardApiResponse('error', null, $className . ' not found'), 200); } + // Handle API requests that fail because of an HTTP status code and return a useful error message if ($this->isHttpException($e)) { $statusCode = $e->getStatusCode();