From 0e3d9a88f6b9e7ea5cc2bb029a616b5f1c373525 Mon Sep 17 00:00:00 2001
From: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com>
Date: Wed, 12 Apr 2023 08:47:52 +0000
Subject: [PATCH] Add error wrapping

---
 dist/index.js            | 23 +++++++++++++++++------
 src/github-api-helper.ts | 24 +++++++++++++++++-------
 2 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/dist/index.js b/dist/index.js
index 00db935..4709ee3 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -1453,6 +1453,7 @@ const path = __importStar(__nccwpck_require__(1017));
 const retryHelper = __importStar(__nccwpck_require__(2155));
 const toolCache = __importStar(__nccwpck_require__(7784));
 const v4_1 = __importDefault(__nccwpck_require__(824));
+const request_error_1 = __nccwpck_require__(537);
 const IS_WINDOWS = process.platform === 'win32';
 function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath, baseUrl) {
     return __awaiter(this, void 0, void 0, function* () {
@@ -1549,12 +1550,22 @@ function downloadArchive(authToken, owner, repo, ref, commit, baseUrl) {
         const download = IS_WINDOWS
             ? octokit.rest.repos.downloadZipballArchive
             : octokit.rest.repos.downloadTarballArchive;
-        const response = yield download({
-            owner: owner,
-            repo: repo,
-            ref: commit || ref
-        });
-        return Buffer.from(response.data); // response.data is ArrayBuffer
+        try {
+            const response = yield download({
+                owner: owner,
+                repo: repo,
+                ref: commit || ref
+            });
+            return Buffer.from(response.data); // response.data is ArrayBuffer
+        }
+        catch (error) {
+            if (error instanceof request_error_1.RequestError) {
+                throw new Error(`Unexpected response from GitHub API. Status: ${error.status}, Data: ${error.message}`);
+            }
+            else {
+                throw error;
+            }
+        }
     });
 }
 
diff --git a/src/github-api-helper.ts b/src/github-api-helper.ts
index 0f5fb73..3e9f9ee 100644
--- a/src/github-api-helper.ts
+++ b/src/github-api-helper.ts
@@ -7,6 +7,7 @@ import * as path from 'path'
 import * as retryHelper from './retry-helper'
 import * as toolCache from '@actions/tool-cache'
 import {default as uuid} from 'uuid/v4'
+import { RequestError } from '@octokit/request-error';
 
 const IS_WINDOWS = process.platform === 'win32'
 
@@ -129,11 +130,20 @@ async function downloadArchive(
   const download = IS_WINDOWS
     ? octokit.rest.repos.downloadZipballArchive
     : octokit.rest.repos.downloadTarballArchive
-  const response = await download({
-    owner: owner,
-    repo: repo,
-    ref: commit || ref
-  })
-
-  return Buffer.from(response.data as ArrayBuffer) // response.data is ArrayBuffer
+    try {
+      const response = await download({
+        owner: owner,
+        repo: repo,
+        ref: commit || ref
+      });
+      return Buffer.from(response.data as ArrayBuffer) // response.data is ArrayBuffer
+    } catch (error) {
+      if (error instanceof RequestError) {
+        throw new Error(
+          `Unexpected response from GitHub API. Status: ${error.status}, Data: ${error.message}`
+        )
+      } else {
+        throw error
+      }
+    }
 }