diff options
author | Julien Dessaux | 2023-05-26 00:04:16 +0200 |
---|---|---|
committer | Julien Dessaux | 2023-05-26 00:04:16 +0200 |
commit | 19107b153e9e3a5e4a758b9db6a867c031467320 (patch) | |
tree | 1d45818111db9903f2976ca323357347d1b25a61 /lib/api.js | |
parent | Updated the lib for the new api (diff) | |
download | spacetraders-19107b153e9e3a5e4a758b9db6a867c031467320.tar.gz spacetraders-19107b153e9e3a5e4a758b9db6a867c031467320.tar.bz2 spacetraders-19107b153e9e3a5e4a758b9db6a867c031467320.zip |
Automated the extraction and delivery loop for a ship
Diffstat (limited to '')
-rw-r--r-- | lib/api.js | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -1,3 +1,5 @@ +import * as fs from 'fs'; + import { getToken } from '../database/config.js'; import { PriorityQueue } from './priority_queue.js'; @@ -58,10 +60,15 @@ function send_this(data) { if (data.request.payload !== undefined) { options['body'] = JSON.stringify(data.request.payload); } + fs.writeFileSync('log', JSON.stringify({event: 'send', date: new Date(), data: data}) + '\n', {flag: 'a+'}); fetch(`https://api.spacetraders.io/v2${data.request.endpoint}`, options) .then(response => response.json()) - .then(response => data.resolve(response)) - .catch(err => data.reject(err)); + .then(response => { + fs.writeFileSync('log', JSON.stringify({event: 'response', date: new Date(), data: response}) + '\n', {flag: 'a+'}); + return data.resolve(response);}) + .catch(err => { + fs.writeFileSync('log', JSON.stringify({event: 'error', date: new Date(), data: err}) + '\n', {flag: 'a+'}); + data.reject(err)}); setTimeout(send_next, 500); } |