Merge pull request #12818 from snipe/fixes/better_error_handling_on_dates

Check for Carbon exception
This commit is contained in:
snipe 2023-04-11 23:36:42 -07:00 committed by GitHub
commit c02bd54826
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 8 deletions

View file

@ -10,7 +10,7 @@ use ArieTimmerman\Laravel\SCIMServer\Exceptions\SCIMException;
use Log;
use Throwable;
use JsonException;
use Carbon\Exceptions\InvalidFormatException;
class Handler extends ExceptionHandler
{
@ -69,16 +69,25 @@ class Handler extends ExceptionHandler
// Invalid JSON exception
// TODO: don't understand why we have to do this when we have the invalidJson() method, below, but, well, whatever
if ($e instanceof JsonException) {
return response()->json(Helper::formatStandardApiResponse('error', null, 'invalid JSON'), 422);
return response()->json(Helper::formatStandardApiResponse('error', null, 'Invalid JSON'), 422);
}
if ($e instanceof SCIMException) {
return response()->json(Helper::formatStandardApiResponse('error', null, 'invalid SCIM Request'), 400);
return response()->json(Helper::formatStandardApiResponse('error', null, 'Invalid SCIM Request'), 400);
}
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
if ($request->ajax() || $request->wantsJson()) {
if ($e instanceof InvalidFormatException) {
return response()->json(Helper::formatStandardApiResponse('error', null, trans('validation.date')), 200);
}
if ($e instanceof \Illuminate\Database\Eloquent\ModelNotFoundException) {
$className = last(explode('\\', $e->getModel()));
return response()->json(Helper::formatStandardApiResponse('error', null, $className . ' not found'), 200);
@ -103,6 +112,8 @@ class Handler extends ExceptionHandler
}
if ($this->isHttpException($e) && (isset($statusCode)) && ($statusCode == '404' )) {
return response()->view('layouts/basic', [
'content' => view('errors/404')

View file

@ -33,9 +33,9 @@ class License extends Depreciable
protected $table = 'licenses';
protected $casts = [
'purchase_date' => 'datetime',
'expiration_date' => 'datetime',
'termination_date' => 'datetime',
'purchase_date' => 'date',
'expiration_date' => 'date',
'termination_date' => 'date',
'category_id' => 'integer',
'company_id' => 'integer',
];

View file

@ -77,7 +77,7 @@
<div class="form-group {{ $errors->has('expiration_date') ? ' has-error' : '' }}">
<label for="expiration_date" class="col-md-3 control-label">{{ trans('admin/licenses/form.expiration') }}</label>
<div class="input-group col-md-3">
<div class="input-group col-md-4">
<div class="input-group date" data-provide="datepicker" data-date-format="yyyy-mm-dd" data-autoclose="true" data-date-clear-btn="true">
<input type="text" class="form-control" placeholder="{{ trans('general.select_date') }}" name="expiration_date" id="expiration_date" value="{{ old('expiration_date', $item->expiration_date) }}">
<span class="input-group-addon"><i class="fas fa-calendar" aria-hidden="true"></i></span>
@ -91,7 +91,7 @@
<div class="form-group {{ $errors->has('termination_date') ? ' has-error' : '' }}">
<label for="termination_date" class="col-md-3 control-label">{{ trans('admin/licenses/form.termination_date') }}</label>
<div class="input-group col-md-3">
<div class="input-group col-md-4">
<div class="input-group date" data-provide="datepicker" data-date-format="yyyy-mm-dd" data-autoclose="true" data-date-clear-btn="true">
<input type="text" class="form-control" placeholder="{{ trans('general.select_date') }}" name="termination_date" id="termination_date" value="{{ old('termination_date', $item->termination_date) }}">
<span class="input-group-addon"><i class="fas fa-calendar" aria-hidden="true"></i></span>