mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-04-06 04:23:16 +08:00
New Response Type
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
12
packages/cache/src/internal/contracts.d.ts
vendored
12
packages/cache/src/internal/contracts.d.ts
vendored
@@ -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
|
||||
}
|
||||
|
||||
11
packages/cache/src/internal/requestUtils.ts
vendored
11
packages/cache/src/internal/requestUtils.ts
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user