Consistent log lines for WebAPI requests
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
parent
3ea1f80495
commit
7cd74ff535
|
@ -239,7 +239,8 @@ async function _promiseAjax(
|
||||||
const redactedURL = options.redactUrl ? options.redactUrl(url) : url;
|
const redactedURL = options.redactUrl ? options.redactUrl(url) : url;
|
||||||
|
|
||||||
const unauthLabel = options.unauthenticated ? ' (unauth)' : '';
|
const unauthLabel = options.unauthenticated ? ' (unauth)' : '';
|
||||||
log.info(`${options.type} ${logType} ${redactedURL}${unauthLabel}`);
|
const logId = `${options.type} ${logType} ${redactedURL}${unauthLabel}`;
|
||||||
|
log.info(logId);
|
||||||
|
|
||||||
const timeout = typeof options.timeout === 'number' ? options.timeout : 10000;
|
const timeout = typeof options.timeout === 'number' ? options.timeout : 10000;
|
||||||
|
|
||||||
|
@ -343,13 +344,13 @@ async function _promiseAjax(
|
||||||
result = await response.textConverted();
|
result = await response.textConverted();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error(options.type, logType, redactedURL, 0, 'Error');
|
log.error(logId, 0, 'Error');
|
||||||
const stack = `${e.stack}\nInitial stack:\n${options.stack}`;
|
const stack = `${e.stack}\nInitial stack:\n${options.stack}`;
|
||||||
throw makeHTTPError('promiseAjax catch', 0, {}, e.toString(), stack);
|
throw makeHTTPError('promiseAjax catch', 0, {}, e.toString(), stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isSuccess(response.status)) {
|
if (!isSuccess(response.status)) {
|
||||||
log.error(options.type, logType, redactedURL, response.status, 'Error');
|
log.error(logId, response.status, 'Error');
|
||||||
|
|
||||||
throw makeHTTPError(
|
throw makeHTTPError(
|
||||||
'promiseAjax: error response',
|
'promiseAjax: error response',
|
||||||
|
@ -366,7 +367,7 @@ async function _promiseAjax(
|
||||||
) {
|
) {
|
||||||
if (options.validateResponse) {
|
if (options.validateResponse) {
|
||||||
if (!_validateResponse(result, options.validateResponse)) {
|
if (!_validateResponse(result, options.validateResponse)) {
|
||||||
log.error(options.type, logType, redactedURL, response.status, 'Error');
|
log.error(logId, response.status, 'Error');
|
||||||
throw makeHTTPError(
|
throw makeHTTPError(
|
||||||
'promiseAjax: invalid response',
|
'promiseAjax: invalid response',
|
||||||
response.status,
|
response.status,
|
||||||
|
@ -378,7 +379,7 @@ async function _promiseAjax(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info(options.type, logType, redactedURL, response.status, 'Success');
|
log.info(logId, response.status, 'Success');
|
||||||
|
|
||||||
if (options.responseType === 'byteswithdetails') {
|
if (options.responseType === 'byteswithdetails') {
|
||||||
assert(result instanceof Uint8Array, 'Expected Uint8Array result');
|
assert(result instanceof Uint8Array, 'Expected Uint8Array result');
|
||||||
|
|
Loading…
Reference in a new issue