Skip to content

Commit 46fc10d

Browse files
committed
handle error in refresh room during loading
1 parent 150be85 commit 46fc10d

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/components/TopBar/TopBar.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,20 @@ export class ListRoomsButton extends React.Component<{}> {
145145
refreshRooms = async () => {
146146
if (this.context.user) {
147147
const token = await this.context.user.getIdToken();
148-
const response = await fetch(
149-
serverPath + `/listRooms?uid=${this.context.user?.uid}&token=${token}`,
150-
);
151-
this.setState({ rooms: await response.json() });
148+
try {
149+
const response = await fetch(
150+
serverPath +
151+
`/listRooms?uid=${this.context.user?.uid}&token=${token}`,
152+
);
153+
if (!response.ok) {
154+
this.setState({ rooms: [] });
155+
return;
156+
}
157+
const data = await response.json();
158+
this.setState({ rooms: Array.isArray(data) ? data : [] });
159+
} catch {
160+
this.setState({ rooms: [] });
161+
}
152162
}
153163
};
154164

0 commit comments

Comments
 (0)