New Response Type

This commit is contained in:
Deepak Dahiya
2022-03-31 09:42:59 +00:00
committed by GitHub
parent b602df7c05
commit 79acd5bac4
5 changed files with 28 additions and 10 deletions
+7 -4
View File
@@ -5,6 +5,7 @@ import {
ITypedResponse
} from '@actions/http-client/interfaces'
import {DefaultRetryDelay, DefaultRetryAttempts} from './constants'
import {ITypedResponseWithErrorMessage} from './contracts'
export function isSuccessStatusCode(statusCode?: number): boolean {
if (!statusCode) {
@@ -94,14 +95,14 @@ export async function retry<T>(
export async function retryTypedResponse<T>(
name: string,
method: () => Promise<ITypedResponse<T>>,
method: () => Promise<ITypedResponseWithErrorMessage<T>>,
maxAttempts = DefaultRetryAttempts,
delay = DefaultRetryDelay
): Promise<ITypedResponse<T>> {
): Promise<ITypedResponseWithErrorMessage<T>> {
return await retry(
name,
method,
(response: ITypedResponse<T>) => response.statusCode,
(response: ITypedResponseWithErrorMessage<T>) => response.statusCode,
maxAttempts,
delay,
// If the error object contains the statusCode property, extract it and return
@@ -111,7 +112,9 @@ export async function retryTypedResponse<T>(
return {
statusCode: error.statusCode,
result: null,
headers: {}
headers: {},
message:error.message,
typeKey:error.result.typeKey
}
} else {
return undefined