diff options
author | Julien Dessaux | 2023-06-03 09:04:27 +0200 |
---|---|---|
committer | Julien Dessaux | 2023-06-03 09:04:27 +0200 |
commit | d0ea2a12bc6dab440564ce55d32e1df6e93d4da9 (patch) | |
tree | 902af87a9d7cb31df3d47d2ed89660c275186f2c | |
parent | Improved ships lib with ships db caching (diff) | |
download | spacetraders-d0ea2a12bc6dab440564ce55d32e1df6e93d4da9.tar.gz spacetraders-d0ea2a12bc6dab440564ce55d32e1df6e93d4da9.tar.bz2 spacetraders-d0ea2a12bc6dab440564ce55d32e1df6e93d4da9.zip |
Handle connection reset event
-rw-r--r-- | lib/api.js | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -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) { |