From e07b3d5c998cdcc65cb92e4a2b996112bb7401a8 Mon Sep 17 00:00:00 2001
From: Kir_Antipov <kp.antipov@gmail.com>
Date: Sun, 26 Sep 2021 20:05:59 +0300
Subject: [PATCH] Added more details to the error message

---
 src/utils/curseforge-utils.ts | 6 +++++-
 src/utils/modrinth-utils.ts   | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/utils/curseforge-utils.ts b/src/utils/curseforge-utils.ts
index 019f2cf..6e13bd6 100644
--- a/src/utils/curseforge-utils.ts
+++ b/src/utils/curseforge-utils.ts
@@ -97,7 +97,11 @@ export async function uploadFile(id: string, data: Record<string, any>, file: Fi
     });
 
     if (!response.ok) {
-        throw new Error(`Failed to upload file: ${response.status} (${response.statusText})`)
+        let errorText = response.statusText;
+        try {
+            errorText += `, ${await response.text()}`;
+        } catch { }
+        throw new Error(`Failed to upload file: ${response.status} (${errorText})`);
     }
 
     return (<{ id: number }>await response.json()).id;
diff --git a/src/utils/modrinth-utils.ts b/src/utils/modrinth-utils.ts
index d98642d..38886a7 100644
--- a/src/utils/modrinth-utils.ts
+++ b/src/utils/modrinth-utils.ts
@@ -23,7 +23,11 @@ export async function createVersion(id: string, data: Record<string, any>, files
     });
 
     if (!response.ok) {
-        throw new Error(`Failed to upload file: ${response.status} (${response.statusText})`)
+        let errorText = response.statusText;
+        try {
+            errorText += `, ${await response.text()}`;
+        } catch { }
+        throw new Error(`Failed to upload file: ${response.status} (${errorText})`);
     }
 
     return (<{ id: string }>await response.json()).id;