Skip to content

Commit 3870d5c

Browse files
committed
fix(errors): exception processing at JSON endpoints
1 parent e946782 commit 3870d5c

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

app/Exceptions/Handler.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ public function render($request, Throwable $e)
6666
if (config('app.debug')) {
6767
return parent::render($request, $e);
6868
}
69-
return response()->view('errors.404', [], 200);
69+
70+
if ($request->expectsJson() || $request->is('api/*')) {
71+
$status = $this->isHttpException($e) ? $e->getStatusCode() : 500;
72+
return response()->json(['message' => 'server error'], $status);
73+
}
74+
75+
return response()->view('errors.404', [], 404);
7076
}
7177
}

app/Http/Controllers/JsonController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct()
2727
{
2828
}
2929

30-
protected function error500(Exception $ex)
30+
protected function error500(\Throwable $ex)
3131
{
3232
Log::error($ex);
3333

app/Http/Controllers/Utils/RequestProcessor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,9 @@ public function processRequest(Closure $callback){
6767
Log::error($ex);
6868
return $this->error500($ex);
6969
}
70+
catch (\Throwable $ex) {
71+
Log::error($ex);
72+
return $this->error500($ex);
73+
}
7074
}
7175
}

0 commit comments

Comments
 (0)