summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2023-06-03 09:04:27 +0200
committerJulien Dessaux2023-06-03 09:04:27 +0200
commitd0ea2a12bc6dab440564ce55d32e1df6e93d4da9 (patch)
tree902af87a9d7cb31df3d47d2ed89660c275186f2c
parentImproved ships lib with ships db caching (diff)
downloadspacetraders-d0ea2a12bc6dab440564ce55d32e1df6e93d4da9.tar.gz
spacetraders-d0ea2a12bc6dab440564ce55d32e1df6e93d4da9.tar.bz2
spacetraders-d0ea2a12bc6dab440564ce55d32e1df6e93d4da9.zip
Handle connection reset event
-rw-r--r--lib/api.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/api.js b/lib/api.js
index ae05c7f..4ee5c5d 100644
--- a/lib/api.js
+++ b/lib/api.js
@@ -68,12 +68,17 @@ function send_this(data) {
return data.resolve(response);})
.catch(err => {
fs.writeFileSync('log', JSON.stringify({event: 'error', date: new Date(), data: err}) + '\n', {flag: 'a+'});
- if (err.cause?.code === 'UND_ERR_CONNECT_TIMEOUT') {
+ switch(err.cause?.code) {
+ case 'ECONNRESET':
send_this(data);
- } else {
+ break;
+ case 'UND_ERR_CONNECT_TIMEOUT':
+ send_this(data);
+ break;
+ default:
data.reject(err)
}});
- setTimeout(send_next, 500);
+ setTimeout(send_next, 400); // 333 should work, but 400 will still allow manual requests to go through during development
}
export function debugLog(ctx) {