Skip to content

Commit

Permalink
Catch exception when fetching server state
Browse files Browse the repository at this point in the history
  • Loading branch information
duogenesis committed Aug 30, 2024
1 parent 1d4c37f commit 63574ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 6 additions & 2 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,12 @@ const App = () => {
}, []);

const fetchServerStatusState = useCallback(async () => {
const response = await fetch(STATUS_URL, {cache: 'no-cache'});
if (!response.ok) {
let response: Response | null = null
try {
response = await fetch(STATUS_URL, {cache: 'no-cache'});
} catch (e) {};

if (response === null || !response.ok) {
// If even the status server is down, things are *very* not-okay. But odds
// are it can't be contacted because the user has a crappy internet
// connection. The "You're offline" notice should still provide some
Expand Down
10 changes: 4 additions & 6 deletions xmpp/xmpp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ const select1 = (query: string, stanza: Element): xpath.SelectedValue => {
};

const login = async (username: string, password: string) => {
console.log('login'); // TODO
if (_xmpp.current) {
return; // Already logged in
}
Expand Down Expand Up @@ -504,7 +505,6 @@ const login = async (username: string, password: string) => {

await _xmpp.current.client.start();
} catch (e) {
_xmpp.current = null;
notify('xmpp-is-online', false);

console.error(e);
Expand Down Expand Up @@ -1042,16 +1042,14 @@ const refreshInbox = async (): Promise<void> => {
};

const logout = async () => {
console.log('logout'); // TODO
if (!_xmpp.current) {
return;
}

const currentClient = _xmpp.current.client;
_xmpp.current = null;

notify('xmpp-is-online', false);
await currentClient.reconnect.stop();
await currentClient.stop().catch(console.warn);
await _xmpp.current.client.reconnect.stop();
await _xmpp.current.client.stop().catch(console.warn);
notify('inbox', null);
_xmpp.current = null;
};
Expand Down

0 comments on commit 63574ae

Please sign in to comment.