mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
many changes from testing
This commit is contained in:
@@ -41,6 +41,9 @@ class Requestor {
|
||||
|
||||
assert(isAbsoluteUrl(this.url));
|
||||
assert(['GET', 'POST'].includes(this.method));
|
||||
|
||||
const {stats} = require('../../').srf.locals;
|
||||
this.stats = stats;
|
||||
}
|
||||
|
||||
get baseUrl() {
|
||||
@@ -65,14 +68,26 @@ class Requestor {
|
||||
const {username, password} = typeof hook === 'object' ? hook : {};
|
||||
|
||||
assert.ok(url, 'Requestor:request url was not provided');
|
||||
assert.ok, (['GET', 'POST'].includes(method), `Requestor:request method must be 'GET' or 'POST' not ${method}`);
|
||||
|
||||
assert.ok, (['GET', 'POST'].includes(method), `Requestor:request method must be 'GET' or 'POST' not ${method}`);
|
||||
|
||||
this.logger.debug({hook, params}, `Requestor:request ${method} ${url}`);
|
||||
const buf = isRelativeUrl(url) ?
|
||||
await this.post(url, params, this.authHeader) :
|
||||
await bent(method, 'buffer', 200, 201)(url, params, basicAuth(username, password));
|
||||
this.logger.debug(`Requestor:request ${method} ${url} succeeded`);
|
||||
const startAt = process.hrtime();
|
||||
|
||||
let buf;
|
||||
try {
|
||||
buf = isRelativeUrl(url) ?
|
||||
await this.post(url, params, this.authHeader) :
|
||||
await bent(method, 'buffer', 200, 201)(url, params, basicAuth(username, password));
|
||||
} catch (err) {
|
||||
this.logger.info({baseUrl: this.baseUrl, url: err.statusCode},
|
||||
`web callback returned unexpected error code ${err.statusCode}`);
|
||||
throw err;
|
||||
}
|
||||
const diff = process.hrtime(startAt);
|
||||
const time = diff[0] * 1e3 + diff[1] * 1e-6;
|
||||
const rtt = time.toFixed(0);
|
||||
this.logger.debug(`Requestor:request ${method} ${url} succeeded in ${rtt}ms`);
|
||||
if (buf) this.stats.histogram('app.hook.response_time', rtt, ['hook_type:app']);
|
||||
|
||||
if (buf && buf.toString().length > 0) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user