+ public function render($request, Throwable $e)
+ {
+ if ($this->isApiRequest($request)) {
+ return $this->renderApiException($e);
+ }
+
+ return parent::render($request, $e);
+ }
+
+ /**
+ * Check if the given request is an API request.
+ */
+ protected function isApiRequest(Request $request): bool
+ {
+ return strpos($request->path(), 'api/') === 0;
+ }
+
+ /**
+ * Render an exception when the API is in use.
+ */
+ protected function renderApiException(Throwable $e): JsonResponse