|
1 | | -import { isStorageError, StorageError, StorageUnknownError } from '../lib/errors' |
| 1 | +import { isStorageError, StorageError, StorageUnknownError, StorageApiError } from '../lib/errors' |
2 | 2 | import { Fetch, get, head, post, put, remove } from '../lib/fetch' |
3 | 3 | import { recursiveToCamel, resolveFetch } from '../lib/helpers' |
4 | 4 | import { |
@@ -600,14 +600,21 @@ export default class StorageFileApi { |
600 | 600 | if (this.shouldThrowOnError) { |
601 | 601 | throw error |
602 | 602 | } |
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 | + } |
605 | 613 |
|
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 } |
608 | 616 | } |
609 | 617 | } |
610 | | - |
611 | 618 | throw error |
612 | 619 | } |
613 | 620 | } |
|
0 commit comments