rittenhop-dev/versions/5.94.2/node_modules/@tryghost/http-stream/lib/HttpStream.js

33 lines
872 B
JavaScript
Raw Normal View History

2024-09-23 19:40:12 -04:00
const request = require('@tryghost/request');
const debug = require('debug')('@tryghost/http-stream');
const GhostError = require('@tryghost/errors');
class HttpStream {
constructor(config) {
this.config = config;
}
async write(data) {
try {
if (typeof data !== 'object') {
throw new GhostError.IncorrectUsageError({message: 'Type Error: Http transport requires log data to be an object'});
}
const options = {
...this.config,
method: 'POST',
json: data
};
const {url} = options;
delete options.url;
return await request(url, options);
} catch (error) {
debug('Failed to ship log', error.message);
return false;
}
}
}
module.exports = HttpStream;