Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Properly handle errors in Upload Api (related to StorageError) #216

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hmpthz
Copy link

@hmpthz hmpthz commented Nov 21, 2024

What kind of change does this PR introduce?

Fix the error handling of upload, update and uploadToSignedUrl APIs so that they properly return StorageError instead of API's error schema.

What is the current behavior?

Multiple issues and PRs have been discussing this error for over a year. #214 #165

There are a bunch of helper functions at lib/fetch.ts that catch errors returned by the server and construct StorageError instance. Nearly all requests are using these helpers, except for uploadOrUpdate and uploadToSignedUrl in StorageFileApi, making their return types inconsistent:

Typescript declarations say the error returns are like:

{
  data: null,
  error: StorageError
}

However, without the helper functions, they actually return the error schema:

{
  data: null,
  error: { error: string, message: string, statusCode: string }
}

What is the new behavior?

This fix replaces raw fetch for uploadOrUpdate and uploadToSignedUrl with post and put helper functions so that their returns match the type declarations.

Additional context

It appears upload APIs are not using helpers because _getRequestParams will force body to be json type, which is an easy fix.

But if you think this part should not be touched, an alternative solution could be just patch the typings.

{
  data: null,
  error: StorageError | ErrorSchema
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant