Skip to content

A free open source IT asset/license management system

Improved commenting

sniped3d464e179ae
diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php
index 1878025217..e1145cd5c4 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();