Merge pull request #495 from metrico/fix/494_axios_error

fix: axios error
This commit is contained in:
akvlad
2024-05-02 14:11:24 +03:00
committed by GitHub
6 changed files with 28 additions and 10 deletions

View File

@ -1,4 +1,7 @@
const path = require('path')
module.exports = {
setupFilesAfterEnv: [path.join(__dirname, '/test/jest.setup.js')]
setupFilesAfterEnv: [path.join(__dirname, '/test/jest.setup.js')],
moduleNameMapper: {
'^axios$': 'axios/dist/node/axios.cjs'
}
}

View File

@ -1363,12 +1363,27 @@ const samplesReadTable = {
*/
const rawRequest = async (query, data, database, config) => {
try {
if (data && !(Buffer.isBuffer(data) || data instanceof Uint8Array || typeof data === 'string')) {
throw new Error('data must be Buffer, Uint8Array or String: currently the data is: ' + typeof data)
}
if (typeof data === 'string') {
data = Buffer.from(data, 'utf8')
}
if (typeof query !== 'string') {
throw new Error('query must be String: currently the query is: ' + typeof query)
}
const getParams = [
(database ? `database=${encodeURIComponent(database)}` : null),
(data ? `query=${encodeURIComponent(query)}` : null)
].filter(p => p)
const url = `${getClickhouseUrl()}/${getParams.length ? `?${getParams.join('&')}` : ''}`
return await axios.post(url, data || query, config)
config = {
...(config || {}),
method: 'post',
url: url,
data: data || query
}
return await axios(config)
} catch (e) {
logger.error('rawRequest error: ' + query)
e.response?.data && logger.error(e.response.data.toString())

10
package-lock.json generated
View File

@ -25,7 +25,7 @@
"@qxip/plugnplay": "^3.3.1",
"@stricjs/router": "^5.0.6",
"@stricjs/utils": "^1.6.1",
"axios": "^0.28.0",
"axios": "^1.6.8",
"basic-auth": "^2.0.1",
"bnf": "^1.0.1",
"csv-writer": "^1.6.0",
@ -3574,11 +3574,11 @@
}
},
"node_modules/axios": {
"version": "0.28.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.28.0.tgz",
"integrity": "sha512-Tu7NYoGY4Yoc7I+Npf9HhUMtEEpV7ZiLH9yndTCoNhcpBH0kwcvFbzYN9/u5QKI5A6uefjsNNWaz5olJVYS62Q==",
"version": "1.6.8",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz",
"integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==",
"dependencies": {
"follow-redirects": "^1.15.0",
"follow-redirects": "^1.15.6",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}

View File

@ -44,7 +44,7 @@
"@qxip/influx-line-protocol-parser": "^0.2.1",
"@qxip/plugnplay": "^3.3.1",
"@stricjs/router": "^5.0.6",
"axios": "^0.28.0",
"axios": "^1.6.8",
"bnf": "^1.0.1",
"csv-writer": "^1.6.0",
"date-fns": "^2.27.0",

View File

@ -13,7 +13,7 @@ cmp ::= "="|"!="|"<="|">="|"<"|">"
cmp_val ::= <number> [<measurement>]
measurement ::= "ns"|"us"|"ms"|"s"|"m"|"h"|"d"
label_name ::= ("." | <ALPHA> | "_") *("." | <ALPHA> | "_" | <DIGITS>)
label_name ::= ("." | <ALPHA> | "-" | "_") *("." | <ALPHA> | "_" | "-" | <DIGITS>)
number ::= ["-"] <DIGITS> ["." <DIGITS>]
attr_selector ::= <label_name> <OWSP> <op> <OWSP> <value>