diff options
Diffstat (limited to 'lib/api.js')
-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); } |