@libj/http
Advanced tools
Comparing version 0.4.6 to 0.5.0
@@ -10,4 +10,15 @@ import { AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
} | ||
declare type LoggerSettingRequestDataLogMapper = (data: LooseObject) => LooseObject; | ||
export type { LoggerSettingRequestDataLogMapper as HttpClientLoggerSettingRequestDataLogMapper }; | ||
interface LoggerSettingOptions { | ||
requestDataLog?: boolean | LoggerSettingRequestDataLogMapper; | ||
} | ||
export { LoggerSettingOptions as HttpClientLoggerSettingOptions }; | ||
declare type LoggerSetting = LoggerInterface | { | ||
logger: LoggerInterface; | ||
options: LoggerSettingOptions; | ||
}; | ||
export { LoggerSetting as HttpClientLoggerSetting }; | ||
export interface HttpClientConfig extends HttpRequestOptions { | ||
logger?: LoggerInterface; | ||
logger?: LoggerSetting; | ||
} | ||
@@ -14,0 +25,0 @@ export declare type HttpHeaders = LooseObject; |
import { AxiosInstance } from 'axios'; | ||
import { LoggerInterface } from '@libj/logger'; | ||
export declare function httpLoggerInterceptor(agent: AxiosInstance, logger: LoggerInterface): void; | ||
import { HttpClientLoggerSetting } from '../client/types'; | ||
export declare function httpLoggerInterceptor(agent: AxiosInstance, loggerSetting: HttpClientLoggerSetting): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.httpLoggerInterceptor = void 0; | ||
function httpLoggerInterceptor(agent, logger) { | ||
var isType_1 = require("../common/isType/isType"); | ||
function httpLoggerInterceptor(agent, loggerSetting) { | ||
var _a = parseLoggerSetting(loggerSetting), logger = _a.logger, loggerOptions = _a.options; | ||
agent.interceptors.response.use(function (response) { | ||
// @ts-ignore | ||
var message = "[http] " + makeEndpoint(response.config) + " " + response.status + " " + response.statusText; | ||
@@ -13,3 +16,3 @@ logger.info(message); | ||
: error.toString(); | ||
var message = "[http] " + makeEndpoint(error.config) + " " + suffix; | ||
var message = "[http] " + makeEndpoint(error.config, loggerOptions) + " " + suffix; | ||
logger.error(message); | ||
@@ -21,7 +24,16 @@ throw error; | ||
/*** Lib ***/ | ||
function makeEndpoint(_a) { | ||
var method = _a.method, baseURL = _a.baseURL, url = _a.url; | ||
var uri = baseURL ? "" + baseURL + url : url; | ||
return method.toUpperCase() + " " + uri; | ||
function parseLoggerSetting(logger) { | ||
return ('options' in logger) ? logger : { logger: logger, options: {} }; | ||
} | ||
function makeEndpoint(_a, loggerOptions) { | ||
var method = _a.method, baseURL = _a.baseURL, url = _a.url, data = _a.data; | ||
var uri = baseURL ? "" + baseURL + url : url, parts = [method.toUpperCase(), uri]; | ||
if (loggerOptions === null || loggerOptions === void 0 ? void 0 : loggerOptions.requestDataLog) { | ||
var finalData = isType_1.isBool(loggerOptions.requestDataLog) | ||
? data | ||
: loggerOptions.requestDataLog(data); | ||
parts.push(JSON.stringify(finalData)); | ||
} | ||
return parts.join(' '); | ||
} | ||
//# sourceMappingURL=httpLoggerInterceptor.js.map |
{ | ||
"dependencies": { | ||
"@libj/http-meta": "0.1.13", | ||
"@libj/logger": "0.1.0", | ||
"@libj/http-meta": "0.1.14", | ||
"@libj/logger": "0.1.1", | ||
"@libj/make-uri": "1.1.15", | ||
@@ -11,3 +11,3 @@ "axios": "^0.21.1", | ||
"name": "@libj/http", | ||
"version": "0.4.6", | ||
"version": "0.5.0", | ||
"description": "Http toolbox", | ||
@@ -36,3 +36,3 @@ "author": "Sergey Poskachey <seregynp@gmail.com>", | ||
], | ||
"gitHead": "30c84cffcfcb40909407cd18325d52c2daa9a6e7" | ||
"gitHead": "ad1d7fef6e303f5b0f50eaa8c9bc2304a12c9058" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20715
283
+ Added@libj/http-meta@0.1.14(transitive)
+ Added@libj/logger@0.1.1(transitive)
- Removed@libj/http-meta@0.1.13(transitive)
- Removed@libj/logger@0.1.0(transitive)
Updated@libj/http-meta@0.1.14
Updated@libj/logger@0.1.1