From 6c85206ce973dc0b45de8991ea49df1e1c0cd313 Mon Sep 17 00:00:00 2001 From: Iain Sproat <68657+iainsproat@users.noreply.github.com> Date: Tue, 11 Mar 2025 09:03:22 +0000 Subject: [PATCH] improve error handling around fetching root object --- packages/objectloader/src/index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/objectloader/src/index.js b/packages/objectloader/src/index.js index 7ddfbcd7b..edd611283 100644 --- a/packages/objectloader/src/index.js +++ b/packages/objectloader/src/index.js @@ -616,10 +616,15 @@ class ObjectLoader { const cachedRootObject = await this.cacheGetObjects([this.objectId]) if (cachedRootObject[this.objectId]) return cachedRootObject[this.objectId] const response = await this.fetch(this.requestUrlRootObj, { headers: this.headers }) - const responseText = await response.text() - if ([401, 403].includes(response.status)) { - throw new ObjectLoaderRuntimeError('You do not have access to the root object!') + if (!response.ok) { + if ([401, 403].includes(response.status)) { + throw new ObjectLoaderRuntimeError('You do not have access to the root object!') + } + throw new ObjectLoaderRuntimeError( + `Failed to fetch root object: ${response.status} ${response.statusText})` + ) } + const responseText = await response.text() this.cacheStoreObjects([`${this.objectId}\t${responseText}`]) return responseText