Automatically retry on temporary errors when using the presence API server

This commit is contained in:
Samuel Elliott
2022-10-26 17:11:01 +01:00
parent 9d290563d8
commit 6f9afb041d
3 changed files with 41 additions and 9 deletions

View File

@@ -441,6 +441,14 @@ function createApp(
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(response, replacer));
} catch (err) {
if (err && 'type' in err && 'code' in err && (err as any).type === 'system') {
const code: string = (err as any).code;
if (code === 'ETIMEDOUT' || code === 'ENOTFOUND' || code === 'EAI_AGAIN') {
res.setHeader('Retry-After', '60');
}
}
res.statusCode = 500;
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({