Show error when searching public rooms fails (#11378)
* Show error when searching public rooms fails * Fix types * Improve test coverage * Improve coverage
This commit is contained in:
parent
b5bfc5be21
commit
2b17fc3221
4 changed files with 63 additions and 13 deletions
|
@ -51,6 +51,7 @@ export const usePublicRoomDirectory = (): {
|
|||
config?: IPublicRoomDirectoryConfig | null;
|
||||
setConfig(config: IPublicRoomDirectoryConfig | null): void;
|
||||
search(opts: IPublicRoomsOpts): Promise<boolean>;
|
||||
error?: Error | true; // true if an unknown error is encountered
|
||||
} => {
|
||||
const [publicRooms, setPublicRooms] = useState<IPublicRoomsChunkRoom[]>([]);
|
||||
|
||||
|
@ -60,6 +61,7 @@ export const usePublicRoomDirectory = (): {
|
|||
|
||||
const [ready, setReady] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<Error | true | undefined>();
|
||||
|
||||
const [updateQuery, updateResult] = useLatestResult<IRoomDirectoryOptions, IPublicRoomsChunkRoom[]>(setPublicRooms);
|
||||
|
||||
|
@ -112,12 +114,14 @@ export const usePublicRoomDirectory = (): {
|
|||
}
|
||||
|
||||
updateQuery(opts);
|
||||
setLoading(true);
|
||||
setError(undefined);
|
||||
try {
|
||||
setLoading(true);
|
||||
const { chunk } = await MatrixClientPeg.safeGet().publicRooms(opts);
|
||||
updateResult(opts, showNsfwPublicRooms ? chunk : chunk.filter(cheapNsfwFilter));
|
||||
return true;
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e : true);
|
||||
console.error("Could not fetch public rooms for params", opts, e);
|
||||
updateResult(opts, []);
|
||||
return false;
|
||||
|
@ -183,5 +187,6 @@ export const usePublicRoomDirectory = (): {
|
|||
config,
|
||||
search,
|
||||
setConfig,
|
||||
error,
|
||||
} as const;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue