mirror of
https://git.mirrors.martin98.com/https://github.com/cyberman54/curl
synced 2025-08-22 12:09:12 +08:00
test
This commit is contained in:
parent
6b2988f68d
commit
f1432d9eda
48
src/util.ts
48
src/util.ts
@ -4,14 +4,14 @@ import setOutput from './output'
|
|||||||
|
|
||||||
export const validateStatusCode = (actualStatusCode: string): void => {
|
export const validateStatusCode = (actualStatusCode: string): void => {
|
||||||
const acceptedStatusCode: string[] = core.getInput('accept')
|
const acceptedStatusCode: string[] = core.getInput('accept')
|
||||||
.split(",").filter(x => x !== "")
|
.split(",").filter(x => x !== "")
|
||||||
.map(x => x.trim());
|
.map(x => x.trim());
|
||||||
if(!acceptedStatusCode.includes(actualStatusCode)){
|
if (!acceptedStatusCode.includes(actualStatusCode)) {
|
||||||
throw new Error(`The accepted status code is ${acceptedStatusCode} but got ${actualStatusCode}`)
|
throw new Error(`The accepted status code is ${acceptedStatusCode} but got ${actualStatusCode}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const buildOutput = (res: AxiosResponse <any>): string => {
|
export const buildOutput = (res: AxiosResponse<any>): string => {
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
"status_code": res.status,
|
"status_code": res.status,
|
||||||
"data": res.data,
|
"data": res.data,
|
||||||
@ -25,31 +25,35 @@ export const sendRequestWithRetry = (config: AxiosRequestConfig): void => {
|
|||||||
const retryArr: string[] = core.getInput('retry').split('/')
|
const retryArr: string[] = core.getInput('retry').split('/')
|
||||||
const numberOfRetry: number = Number(retryArr[0])
|
const numberOfRetry: number = Number(retryArr[0])
|
||||||
const backoff: number = Number(retryArr[1])
|
const backoff: number = Number(retryArr[1])
|
||||||
core.debug(`retry: ${countRetry}`)
|
process.on('uncaughtException', function (err) {
|
||||||
do{
|
countRetry += 1
|
||||||
try{
|
core.info(`retry: ${countRetry}`)
|
||||||
axios(config)
|
if (countRetry <= numberOfRetry) {
|
||||||
|
sleep(backoff)
|
||||||
|
} else {
|
||||||
|
core.setFailed(err.message)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
do {
|
||||||
|
axios(config)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
exit = true
|
exit = true
|
||||||
setOutput(res)
|
setOutput(res)
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
throw new Error(err)
|
countRetry += 1
|
||||||
|
core.info(`retry: ${countRetry}`)
|
||||||
|
if (countRetry <= numberOfRetry) {
|
||||||
|
sleep(backoff)
|
||||||
|
} else {
|
||||||
|
exit = true
|
||||||
|
core.setFailed(err)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}catch(err){
|
} while (!exit)
|
||||||
countRetry += 1
|
|
||||||
core.info(`retry: ${countRetry}`)
|
|
||||||
if(countRetry <= numberOfRetry){
|
|
||||||
sleep(backoff)
|
|
||||||
}else{
|
|
||||||
exit = true
|
|
||||||
core.setFailed(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}while(!exit)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sleep(ms: number) {
|
function sleep(ms: number) {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user