fix: 🐛 Handle when requests to client daemon are returning 403 (#2105)

This commit is contained in:
Zhihe Li authored and GitHub committed 2024-01-23 16:31:21 -05:00
1 parent 24fdd926f1
commit 5f9a66e421
1 file changed
+19 -1
@@ -104,7 +104,8 @@ export default class ClientDaemonHandler {
filters,
});
}
const auth_token_id = this.session.data?.authenticated?.id;
const sessionData = this.session.data?.authenticated;
const auth_token_id = sessionData?.id;
remainingQuery = {
...remainingQuery,
query: searchQuery,
@@ -119,6 +120,23 @@ export default class ClientDaemonHandler {
remainingQuery,
);
} catch (e) {
// If we got a 403, most likely the client daemon was restarted and our token is no longer valid
// I'm not sure if we can get a 401 since we always send a token but we'll handle it in the same way
if (e.statusCode === 403 || e.statusCode === 401) {
await this.ipc.invoke('addTokenToClientDaemon', {
tokenId: auth_token_id,
token: sessionData?.token,
});
try {
clientDaemonResults = await this.ipc.invoke(
'searchClientDaemon',
remainingQuery,
);
} catch {
// If it fails again just fall back to fetching controller data
}
}
return fetchControllerData(context, next);
}