mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-09 16:24:51 +00:00
Update Exception handler to report validation message bag errors
This commit is contained in:
parent
b1fe0e8b3a
commit
74905ba1d0
1 changed files with 10 additions and 1 deletions
|
@ -68,11 +68,20 @@ class Handler extends ExceptionHandler
|
||||||
*/
|
*/
|
||||||
public function render($request, Throwable $exception)
|
public function render($request, Throwable $exception)
|
||||||
{
|
{
|
||||||
if ($request->wantsJson())
|
if ($exception instanceof \Illuminate\Validation\ValidationException && $request->wantsJson()) {
|
||||||
|
return response()->json(
|
||||||
|
[
|
||||||
|
'message' => $exception->getMessage(),
|
||||||
|
'errors' => $exception->validator->getMessageBag()
|
||||||
|
],
|
||||||
|
method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : 500
|
||||||
|
);
|
||||||
|
} else if ($request->wantsJson()) {
|
||||||
return response()->json(
|
return response()->json(
|
||||||
['error' => $exception->getMessage()],
|
['error' => $exception->getMessage()],
|
||||||
method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : 500
|
method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : 500
|
||||||
);
|
);
|
||||||
|
}
|
||||||
return parent::render($request, $exception);
|
return parent::render($request, $exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue