Skip to content

Commit 195ca1b

Browse files
SumitKumar-17mandarini
authored andcommitted
fix(storage): correct exists() error handling for non-existent files
1 parent 2d0bd77 commit 195ca1b

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

packages/core/storage-js/src/packages/StorageFileApi.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isStorageError, StorageError, StorageUnknownError } from '../lib/errors'
1+
import { isStorageError, StorageError, StorageUnknownError, StorageApiError } from '../lib/errors'
22
import { Fetch, get, head, post, put, remove } from '../lib/fetch'
33
import { recursiveToCamel, resolveFetch } from '../lib/helpers'
44
import {
@@ -600,14 +600,21 @@ export default class StorageFileApi {
600600
if (this.shouldThrowOnError) {
601601
throw error
602602
}
603-
if (isStorageError(error) && error instanceof StorageUnknownError) {
604-
const originalError = error.originalError as unknown as { status: number }
603+
if (isStorageError(error)) {
604+
// Check for both StorageApiError (which has status directly) and StorageUnknownError (with originalError)
605+
let status: number | undefined
606+
607+
if (error instanceof StorageApiError) {
608+
status = error.status
609+
} else if (error instanceof StorageUnknownError) {
610+
const originalError = error.originalError as unknown as { status: number }
611+
status = originalError?.status
612+
}
605613

606-
if ([400, 404].includes(originalError?.status)) {
607-
return { data: false, error }
614+
if (status && [400, 404].includes(status)) {
615+
return { data: false, error: null }
608616
}
609617
}
610-
611618
throw error
612619
}
613620
}

0 commit comments

Comments
 (0)