Skip to content

Commit 43889d7

Browse files
committed
Simplify error logging for failed update requests
1 parent b3efc7b commit 43889d7

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/index.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,18 +233,36 @@ export async function runHTK(options: {
233233
updateMutex.runExclusive(() =>
234234
(<Promise<void>> updateCommand.run(['stable']))
235235
.catch((error) => {
236-
// Received successful update that wants to restart the server
237-
if (isErrorLike(error) && error.code === 'EEXIT') {
238-
// Block future update checks for one hour.
239-
240-
// If we don't, we'll redownload the same update again every check.
241-
// We don't want to block it completely though, in case this server
242-
// stays open for a very long time.
243-
return delay(1000 * 60 * 60);
236+
if (isErrorLike(error)) {
237+
// Did we receive a successful update, that wants to restart the server:
238+
if (error.code === 'EEXIT') {
239+
// Block future update checks for one hour.
240+
241+
// If we don't, we'll redownload the same update again every check.
242+
// We don't want to block it completely though, in case this server
243+
// stays open for a very long time.
244+
return delay(1000 * 60 * 60);
245+
}
246+
247+
// Report any HTTP response errors cleanly & explicitly:
248+
if (error.statusCode) {
249+
let url: string | undefined;
250+
if ('http' in error) {
251+
const request = (error as any).http?.request;
252+
url = `${request?.protocol}//${request?.host}${request?.path}`
253+
}
254+
255+
logError(`Failed to check for updates due to ${error.statusCode} response ${
256+
url
257+
? `from ${url}`
258+
: 'from unknown URL'
259+
}`);
260+
return;
261+
}
244262
}
245263

246-
console.log(error);
247-
logError('Failed to check for updates');
264+
console.log(error.message);
265+
logError(`Failed to check for updates: ${error.message}`);
248266
})
249267
);
250268
});

src/util/error.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type ErrorLike = Partial<Error> & {
44
cmd?: string;
55
signal?: string;
66
status?: number;
7+
statusCode?: number;
78
};
89

910
// Useful to easily cast and then examine errors that are otherwise 'unknown':

0 commit comments

Comments
 (0)