improve error handling around fetching root object

This commit is contained in:
Iain Sproat
2025-03-11 09:03:22 +00:00
parent c2de9c2826
commit 6c85206ce9
+8 -3
View File
@@ -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