frontend client for gemstone. decentralised workplace app

refactor: don't throw on invalid session

serenity 0f91f36f 1f0b7387

Changed files
+25 -17
src
components
Chat
lib
providers
+7 -5
src/components/Chat/index.tsx
···
export const Chat = ({ channelAtUri }: { channelAtUri: AtUri }) => {
const [inputText, setInputText] = useState("");
-
const { messages, sendMessageToChannel, isConnected } =
-
useChannel(channelAtUri);
const record = useChannelRecordByAtUriObject(channelAtUri);
const { semantic } = useCurrentPalette();
const { typography, atoms } = useFacet();
+
const channel = useChannel(channelAtUri);
+
const { isLoading } = useProfile();
+
+
if (!channel) return <></>;
+
+
const { messages, sendMessageToChannel, isConnected } = channel;
const handleSend = () => {
if (inputText.trim()) {
···
}
};
-
const { isLoading } = useProfile();
-
if (!record)
return (
<View>
<Text>
-
Something has gone wrong. Could not resolve channel record
+
Something has gone wrong.Could not resolve channel record
from given at:// URI.
</Text>
</View>
+17 -9
src/lib/hooks/useChannel.ts
···
const { sessionInfo, socket } = findChannelSession(channel);
useEffect(() => {
-
if (!sessionInfo)
-
throw new Error(
+
if (!sessionInfo) {
+
console.warn(
"Channel did not resolve to a valid sessionInfo object.",
);
-
if (!socket)
-
throw new Error(
+
return;
+
}
+
if (!socket) {
+
console.warn(
"Session info did not resolve to a valid websocket connection. This should not happen and is likely a bug. Check the sessions map object.",
);
+
return;
+
}
// attach handlers here
···
};
}, [socket, sessionInfo, channel]);
-
if (!oAuthSession) throw new Error("No OAuth session");
-
if (!sessionInfo)
-
throw new Error(
+
if (!oAuthSession) {console.warn("No OAuth session"); return }
+
if (!sessionInfo) {
+
console.warn(
"Channel did not resolve to a valid sessionInfo object.",
);
-
if (!socket)
-
throw new Error(
+
return;
+
}
+
if (!socket) {
+
console.warn(
"Session info did not resolve to a valid websocket connection. This should not happen and is likely a bug. Check the sessions map object.",
);
+
return;
+
}
const channelStringified = atUriToString(channel);
+1 -3
src/providers/authed/SessionsProvider.tsx
···
console.log("tried to find", channel);
if (!sessionInfo)
-
throw new Error(
-
"Provided channel at:// URI (object) could not be found in any existing lattice sessions",
-
);
+
return { sessionInfo: undefined, socket: undefined };
return { sessionInfo, socket: sessionsMap.get(sessionInfo) };
},