From 3dc7a7756c06e2ebedf00785f3b8e466481177c1 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 11 Sep 2026 17:19:49 +0530 Subject: [PATCH] fix(errors): return JSON errors to SDK requests on redirect routes Routes with an error view rendered the HTML page for every failure, including SDK calls that read the redirect themselves. Render the view only when the request carries no x-sdk-name header, since SDKs also send accept: text/html to these routes. --- app/controllers/general.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 83c19c359b..40a0751174 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -1416,7 +1416,12 @@ Http::error() ->addHeader('Pragma', 'no-cache') ->setStatusCode($code); - $template = $error->getView() ?? (($route) ? $route->getLabel('error', null) : null); + $template = $error->getView(); + + // SDKs send `accept: text/html` to these routes too, so only non-SDK requests get the error page + if ($template === null && $route && $request->getHeaderLine('x-sdk-name') === '') { + $template = $route->getLabel('error', null); + } // TODO: Ideally use group 'api' here, but all wildcard routes seem to have 'api' at the moment if (empty($route) || !\str_starts_with($route->getPath(), '/v1')) {