Compare commits
3 commits
main
...
alex/could
Author | SHA1 | Date | |
---|---|---|---|
|
c908162b7d | ||
|
7dabd65d9f | ||
|
83ceb42acf |
2 changed files with 32 additions and 16 deletions
|
@ -34,7 +34,18 @@ export class HealthTreeItemProvider implements vscode.TreeDataProvider<vscode.Tr
|
||||||
|
|
||||||
// get children for root
|
// get children for root
|
||||||
if (element === undefined) {
|
if (element === undefined) {
|
||||||
const health = await promiseWithTimeout<AppwriteHealth | undefined>(10000, async () => await healthClient?.checkup(), 'Health request timed out');
|
try {
|
||||||
|
const health = await promiseWithTimeout<AppwriteHealth | undefined>(
|
||||||
|
10000,
|
||||||
|
async () => {
|
||||||
|
try {
|
||||||
|
return await healthClient?.checkup();
|
||||||
|
} catch (e) {
|
||||||
|
vscode.window.showErrorMessage('Could not connect to Appwrite project');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Health request timed out"
|
||||||
|
);
|
||||||
if (health === undefined) {
|
if (health === undefined) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -49,6 +60,9 @@ export class HealthTreeItemProvider implements vscode.TreeDataProvider<vscode.Tr
|
||||||
},
|
},
|
||||||
...healthItems,
|
...healthItems,
|
||||||
];
|
];
|
||||||
|
} catch (e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
import { window } from 'vscode';
|
||||||
|
|
||||||
export const promiseWithTimeout = <T>(timeoutMs: number, promise: () => Promise<T>, failureMessage?: string): Promise<T> => {
|
export const promiseWithTimeout = <T>(timeoutMs: number, promise: () => Promise<T>, failureMessage?: string): Promise<T> => {
|
||||||
let timeoutHandle: NodeJS.Timeout;
|
let timeoutHandle: NodeJS.Timeout;
|
||||||
const timeoutPromise = new Promise<never>((resolve, reject) => {
|
const timeoutPromise = new Promise<never>(() => {
|
||||||
timeoutHandle = setTimeout(() => reject(new Error(failureMessage)), timeoutMs);
|
timeoutHandle = setTimeout(() => window.showErrorMessage(failureMessage ?? 'Request timed out'), timeoutMs);
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.race([promise(), timeoutPromise]).then((result) => {
|
return Promise.race([promise(), timeoutPromise]).then((result) => {
|
||||||
|
|
Loading…
Reference in a new issue