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

View File

@@ -13,7 +13,8 @@ import {
InternalCacheOptions,
CommitCacheRequest,
ReserveCacheRequest,
ReserveCacheResponse
ReserveCacheResponse,
ITypedResponseWithErrorMessage
} from './contracts'
import {downloadCacheHttpClient, downloadCacheStorageSDK} from './downloadUtils'
import {
@@ -143,7 +144,7 @@ export async function reserveCache(
key: string,
paths: string[],
options?: InternalCacheOptions
): Promise<ITypedResponse<ReserveCacheResponse>> {
): Promise<ITypedResponseWithErrorMessage<ReserveCacheResponse>> {
const httpClient = createHttpClient()
const version = getCacheVersion(paths, options?.compressionMethod)
@@ -158,6 +159,7 @@ export async function reserveCache(
reserveCacheRequest
)
)
console.log(response)
return response
}

View File

@@ -1,4 +1,12 @@
import {CompressionMethod} from './constants'
import {
ITypedResponse
} from '@actions/http-client/interfaces'
export interface ITypedResponseWithErrorMessage<T> extends ITypedResponse<T> {
message?: string
typeKey?: string
}
export interface ArtifactCacheEntry {
cacheKey?: string
@@ -25,3 +33,7 @@ export interface InternalCacheOptions {
compressionMethod?: CompressionMethod
cacheSize?: number
}
export interface CommitCacheRequest {
size: number
}

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