Fix api error handling

This commit is contained in:
2024-09-25 13:30:58 +02:00
parent 83857507ea
commit 3ba3192800

View File

@@ -179,18 +179,16 @@ export default function RoomsList() {
refetch(); refetch();
onClose(); onClose();
} catch (err) { } catch (err) {
if (err instanceof ApiError) { if (
const apiError = err as ApiError; err instanceof ApiError &&
if ( err.status === 400 &&
apiError.status === 400 && (err.body as any).detail == "Room name is not unique"
(apiError.body as any).detail == "Room name is not unique" ) {
) { setNameError(
setNameError( "This room name is already taken. Please choose a different name.",
"This room name is already taken. Please choose a different name.", );
); } else {
} else { setNameError("An error occurred. Please try again.");
setNameError("An error occurred. Please try again.");
}
} }
} }
}; };