From a19d4d5418de86a3d631108b831a86c2749523bf Mon Sep 17 00:00:00 2001 From: Wv5twkFEKh54vo4tta9yu7dHa3 <61561059+Wv5twkFEKh54vo4tta9yu7dHa3@users.noreply.github.com> Date: Tue, 20 Apr 2021 18:18:42 +0200 Subject: [PATCH] Use same json error format as Mastodon As documented in the Mastodon API ( https://docs.joinmastodon.org/entities/error/ ), error responses use "error" as the key for the value, instead of Laravel's default (which is "message") --- app/Exceptions/Handler.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 23dbecd49..13534549f 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -48,6 +48,11 @@ class Handler extends ExceptionHandler */ public function render($request, Throwable $exception) { + if ($request->wantsJson()) + return response()->json( + ['error' => $exception->getMessage()], + method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : 500 + ); return parent::render($request, $exception); } }