Better error handling when server room list is private
authorAjay Bura <ajbura@gmail.com>
Sun, 3 Oct 2021 04:23:54 +0000 (09:53 +0530)
committerAjay Bura <ajbura@gmail.com>
Sun, 3 Oct 2021 04:23:54 +0000 (09:53 +0530)
Signed-off-by: Ajay Bura <ajbura@gmail.com>
src/app/organisms/public-rooms/PublicRooms.jsx

index b7d2dbb5336549fbc99c2cbc8e7f3d2ed0fd040b..2340129858ce581050ff1f99a027ea10da15cf66 100644 (file)
@@ -137,16 +137,22 @@ function PublicRooms({ isOpen, searchTerm, onRequestClose }) {
       updateNextBatch(result.next_batch);
       updateIsSearching(false);
       updateIsViewMore(false);
-      if (totalRooms.length === 0 && inputRoomName !== '') {
+      if (totalRooms.length === 0) {
         updateSearchQuery({
-          error: `No result found for "${inputRoomName}" on ${inputHs}`,
+          error: inputRoomName === ''
+            ? `No public rooms on ${inputHs}`
+            : `No result found for "${inputRoomName}" on ${inputHs}`,
           alias: isInputAlias ? inputRoomName : null,
         });
       }
     } catch (e) {
       updatePublicRooms([]);
+      let err = 'Something went wrong!';
+      if (e?.httpStatus >= 400 && e?.httpStatus < 500) {
+        err = e.message;
+      }
       updateSearchQuery({
-        error: 'Something went wrong!',
+        error: err,
         alias: isInputAlias ? inputRoomName : null,
       });
       updateIsSearching(false);
@@ -241,20 +247,12 @@ function PublicRooms({ isOpen, searchTerm, onRequestClose }) {
             )
           }
           {
-            typeof searchQuery.name !== 'undefined' && !isSearching && publicRooms.length !== 0 && (
+            typeof searchQuery.name !== 'undefined' && !isSearching && (
               searchQuery.name === ''
                 ? <Text variant="b2">{`Public rooms on ${searchQuery.homeserver}.`}</Text>
                 : <Text variant="b2">{`Search result for "${searchQuery.name}" on ${searchQuery.homeserver}.`}</Text>
             )
           }
-          {
-             typeof searchQuery.name !== 'undefined' && !isSearching && publicRooms.length === 0
-              && (
-              <div className="flex--center">
-                <Text variant="b2">{`There are no public rooms on ${searchQuery.homeserver}.`}</Text>
-              </div>
-              )
-          }
           { searchQuery.error && (
             <>
               <Text className="public-rooms__search-error" variant="b2">{searchQuery.error}</Text>