another day, another correction/improvement/refactor commit

This commit is contained in:
2024-08-09 01:01:17 +05:30
parent b7d6f06ff2
commit 41fff1d406
11 changed files with 238 additions and 264 deletions

View File

@@ -1,52 +0,0 @@
const axios = require('axios');
const { baseAPIURL, accountsAPIURL } = require("../constants");
const logger = require('./logger')(module);
const authInstance = axios.default.create({
baseURL: accountsAPIURL,
timeout: 20000,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic ' + (Buffer.from(process.env.CLIENT_ID + ':' + process.env.CLIENT_SECRET).toString('base64'))
},
});
const axiosInstance = axios.default.create({
baseURL: baseAPIURL,
timeout: 20000,
headers: {
'Content-Type': 'application/json'
},
});
axiosInstance.interceptors.request.use(config => {
logger.http("API call", {
url: config.url,
method: config.method,
params: config.params ?? {},
headers: Object.keys(config.headers),
});
return config;
});
axiosInstance.interceptors.response.use(
(response) => response,
(error) => {
logger.warn("AxiosError", {
error: {
name: error.name,
code: error.code,
message: error.message,
stack: error.stack,
},
req: error.config,
});
return Promise.reject(error);
}
);
module.exports = {
authInstance,
axiosInstance
};

View File

@@ -32,7 +32,7 @@ class myGraph {
}
/**
* @param {type} node
* @param {string} node
* @returns {string[]}
*/
getDirectHeads(node) {
@@ -40,7 +40,7 @@ class myGraph {
}
/**
* @param {type} node
* @param {string} node
* @returns {string[]}
*/
getDirectTails(node) {

View File

@@ -28,7 +28,7 @@ const logFormat = printf(({ level, message, label, timestamp, ...meta }) => {
}
const { stack, ...rest } = meta.error;
return `${timestamp} [${label}] ${level}: ${message}${metaFormat(rest)}\n` +
`${stack}`;
`${stack ?? ''}`;
}
return `${timestamp} [${label}] ${level}: ${message}${metaFormat(meta)}`;
});