Display a somewhat meaningful message when the package list inaccessible
authorAlexander Ebert <ebert@woltlab.com>
Tue, 22 Dec 2020 17:48:21 +0000 (18:48 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 22 Dec 2020 17:48:21 +0000 (18:48 +0100)
wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php

index 376a5079bb0c71454289dfcb5ec6ae22b0932299..742e3e685842c5c4b5cd67d1277cb7690051202f 100644 (file)
@@ -13,6 +13,7 @@ use wcf\system\SingletonFactory;
 use wcf\system\WCF;
 use wcf\util\HTTPRequest;
 use wcf\util\JSON;
+use wcf\util\StringUtil;
 use wcf\util\XML;
 
 /**
@@ -79,8 +80,17 @@ class PackageUpdateDispatcher extends SingletonFactory {
                                $errorMessage = $e->getMessage();
                        }
                        catch (PackageUpdateUnauthorizedException $e) {
-                               $reply = $e->getRequest()->getReply();
-                               list($errorMessage) = reset($reply['httpHeaders']);
+                               $body = $e->getRequest()->getReply()['body'];
+                               
+                               // Try to find the page <title>.
+                               if (preg_match('~<title>(?<title>.*?)</title>~', $body, $matches)) {
+                                       $errorMessage = $matches['title'];
+                               }
+                               else {
+                                       $errorMessage = $body;
+                               }
+                               
+                               $errorMessage = mb_substr(StringUtil::trim(strip_tags($errorMessage)), 0, 65000);
                        }
                        
                        if ($errorMessage) {