mirror of
https://github.com/flarum/core.git
synced 2025-10-18 18:26:07 +02:00
Improve error handling somewhat
- Fix composer crashing/not showing alert on error - Make a general ValidationException which takes an array of field ⇒ messages to be outputted nicely by the API
This commit is contained in:
@@ -18,7 +18,7 @@ abstract class JsonApiAction implements Action
|
||||
*/
|
||||
public function handle(Request $request)
|
||||
{
|
||||
// TODO: Move this error handling code to middleware?
|
||||
// TODO: This is gross. Move this error handling code to middleware?
|
||||
try {
|
||||
return $this->respond($request);
|
||||
} catch (ValidationException $e) {
|
||||
@@ -30,6 +30,12 @@ abstract class JsonApiAction implements Action
|
||||
];
|
||||
}
|
||||
return new JsonResponse(['errors' => $errors], 422);
|
||||
} catch (\Flarum\Core\Exceptions\ValidationException $e) {
|
||||
$errors = [];
|
||||
foreach ($e->getMessages() as $path => $detail) {
|
||||
$errors[] = compact('path', 'detail');
|
||||
}
|
||||
return new JsonResponse(['errors' => $errors], 422);
|
||||
} catch (PermissionDeniedException $e) {
|
||||
return new JsonResponse(null, 401);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
|
Reference in New Issue
Block a user