mirror of
https://git.mirrors.martin98.com/https://github.com/cyberman54/curl
synced 2025-08-22 02:59:13 +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 => {
|
||||
const acceptedStatusCode: string[] = core.getInput('accept')
|
||||
.split(",").filter(x => x !== "")
|
||||
.map(x => x.trim());
|
||||
if(!acceptedStatusCode.includes(actualStatusCode)){
|
||||
.split(",").filter(x => x !== "")
|
||||
.map(x => x.trim());
|
||||
if (!acceptedStatusCode.includes(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({
|
||||
"status_code": res.status,
|
||||
"data": res.data,
|
||||
@ -25,31 +25,35 @@ export const sendRequestWithRetry = (config: AxiosRequestConfig): void => {
|
||||
const retryArr: string[] = core.getInput('retry').split('/')
|
||||
const numberOfRetry: number = Number(retryArr[0])
|
||||
const backoff: number = Number(retryArr[1])
|
||||
core.debug(`retry: ${countRetry}`)
|
||||
do{
|
||||
try{
|
||||
axios(config)
|
||||
process.on('uncaughtException', function (err) {
|
||||
countRetry += 1
|
||||
core.info(`retry: ${countRetry}`)
|
||||
if (countRetry <= numberOfRetry) {
|
||||
sleep(backoff)
|
||||
} else {
|
||||
core.setFailed(err.message)
|
||||
}
|
||||
})
|
||||
do {
|
||||
axios(config)
|
||||
.then(res => {
|
||||
exit = true
|
||||
setOutput(res)
|
||||
})
|
||||
.catch(err => {
|
||||
throw new Error(err)
|
||||
.catch(err => {
|
||||
countRetry += 1
|
||||
core.info(`retry: ${countRetry}`)
|
||||
if (countRetry <= numberOfRetry) {
|
||||
sleep(backoff)
|
||||
} else {
|
||||
exit = true
|
||||
core.setFailed(err)
|
||||
}
|
||||
})
|
||||
}catch(err){
|
||||
countRetry += 1
|
||||
core.info(`retry: ${countRetry}`)
|
||||
if(countRetry <= numberOfRetry){
|
||||
sleep(backoff)
|
||||
}else{
|
||||
exit = true
|
||||
core.setFailed(err)
|
||||
}
|
||||
}
|
||||
}while(!exit)
|
||||
} while (!exit)
|
||||
}
|
||||
|
||||
function sleep(ms: number) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user