diff --git a/packages/artifact/src/internal/shared/artifact-twirp-client.ts b/packages/artifact/src/internal/shared/artifact-twirp-client.ts index dde3d4a4..c59fcc0f 100644 --- a/packages/artifact/src/internal/shared/artifact-twirp-client.ts +++ b/packages/artifact/src/internal/shared/artifact-twirp-client.ts @@ -59,10 +59,10 @@ class ArtifactHttpClient implements Rpc { 'Content-Type': contentType } try { - const response = await this.retryableRequest(async () => + const {body} = await this.retryableRequest(async () => this.httpClient.post(url, JSON.stringify(data), headers) ) - const body = await response.readBody() + return JSON.parse(body) } catch (error) { throw new Error(`Failed to ${method}: ${error.message}`) @@ -71,7 +71,7 @@ class ArtifactHttpClient implements Rpc { async retryableRequest( operation: () => Promise - ): Promise { + ): Promise<{response: HttpClientResponse, body: string}> { let attempt = 0 let errorMessage = '' while (attempt < this.maxAttempts) { @@ -80,11 +80,14 @@ class ArtifactHttpClient implements Rpc { try { const response = await operation() const statusCode = response.message.statusCode - debug(`[Response] ${response.message.statusCode}`) - debug(JSON.stringify(response.message.headers, null, 2)) + const raw = await response.readBody() + const body = JSON.parse(raw) + debug(`[Response] - ${response.message.statusCode}`) + debug(`Headers: ${JSON.stringify(response.message.headers, null, 2)}`) + debug(`Body: ${JSON.stringify(body, null, 2)}`) if (this.isSuccessStatusCode(statusCode)) { - return response + return {response, body} } isRetryable = this.isRetryableHttpStatusCode(statusCode) diff --git a/packages/artifact/src/internal/upload/upload-artifact.ts b/packages/artifact/src/internal/upload/upload-artifact.ts index 55921252..e880102f 100644 --- a/packages/artifact/src/internal/upload/upload-artifact.ts +++ b/packages/artifact/src/internal/upload/upload-artifact.ts @@ -40,11 +40,6 @@ export async function uploadArtifact( ) } - const zipUploadStream = await createZipUploadStream( - zipSpecification, - options?.compressionLevel - ) - // get the IDs needed for the artifact creation const backendIds = getBackendIdsFromToken() @@ -73,6 +68,11 @@ export async function uploadArtifact( ) } + const zipUploadStream = await createZipUploadStream( + zipSpecification, + options?.compressionLevel + ) + // Upload zip to blob storage const uploadResult = await uploadZipToBlobStorage( createArtifactResp.signedUploadUrl,