Prefer JSON error responses over HTML
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 13 Apr 2023 14:51:46 +0000 (16:51 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 14 Apr 2023 11:54:52 +0000 (13:54 +0200)
wcfsetup/install/files/lib/http/error/NotFoundHandler.class.php
wcfsetup/install/files/lib/http/error/OfflineHandler.class.php
wcfsetup/install/files/lib/http/error/PermissionDeniedHandler.class.php
wcfsetup/install/files/lib/http/error/XsrfValidationFailedHandler.class.php
wcfsetup/install/files/lib/http/middleware/HandleValinorMappingErrors.class.php

index 28c7d83a87300ed25d149290b167b91f12e90577..c1df968e0126d950bdb1439201c95637d1910141 100644 (file)
@@ -36,8 +36,8 @@ final class NotFoundHandler implements RequestHandlerInterface
         SessionHandler::getInstance()->disableTracking();
 
         $preferredType = Helper::getPreferredContentType($request, [
-            'text/html',
             'application/json',
+            'text/html',
         ]);
 
         return match ($preferredType) {
index 2e63f858108b022be8f80c6b0a760a1ce5923748..d66c7d17bc50fd1e4bc39b2c50124da743c27ab9 100644 (file)
@@ -31,8 +31,8 @@ final class OfflineHandler implements RequestHandlerInterface
         NoticeHandler::disableNotices();
 
         $preferredType = Helper::getPreferredContentType($request, [
-            'text/html',
             'application/json',
+            'text/html',
         ]);
 
         return HeaderUtil::withNoCacheHeaders(match ($preferredType) {
index 88ea301ef4d91e43d8d511798203a395ebda73b6..b30a4ce4878ede4362fe70c812b522665f42693b 100644 (file)
@@ -38,8 +38,8 @@ final class PermissionDeniedHandler implements RequestHandlerInterface
         SessionHandler::getInstance()->disableTracking();
 
         $preferredType = Helper::getPreferredContentType($request, [
-            'text/html',
             'application/json',
+            'text/html',
         ]);
 
         return match ($preferredType) {
index af1047c9dc9a136817706936e837e9c97fdcf448..0049cdb7ec05ab95b046a746f398f7ca349e3829 100644 (file)
@@ -36,8 +36,8 @@ final class XsrfValidationFailedHandler implements RequestHandlerInterface
         SessionHandler::getInstance()->disableTracking();
 
         $preferredType = Helper::getPreferredContentType($request, [
-            'text/html',
             'application/json',
+            'text/html',
         ]);
 
         return match ($preferredType) {
index 7e4b1733cef3f9abbe3f97af2d397d5434f4f515..27f4b06d68ef16f5b7d9c66531b39e206dca47b8 100644 (file)
@@ -39,8 +39,8 @@ final class HandleValinorMappingErrors implements MiddlewareInterface
                 ->formatWith(new PrependPath());
 
             $preferredType = Helper::getPreferredContentType($request, [
-                'text/html',
                 'application/json',
+                'text/html',
             ]);
 
             return match ($preferredType) {