storage-js icon indicating copy to clipboard operation
storage-js copied to clipboard

fix: StorageError shape to match returned errors from API

Open putcho01 opened this issue 1 year ago • 1 comments

What kind of change does this PR introduce?

#165

What is the current behavior?

The StorageApiError class defined in storage-js has a status field. The StorageError defined in storage-api has a statusCode field.

This mismatch make it difficult to correctly handle errors on the frontend. I'd like to use the isStorageError function defined in storage-js, but it does not recognize errors thrown from the API

What is the new behavior?

Update StorageApiError class and error handling to match API returned errors

  • Change StorageApiError class in src/lib/errors.ts to have a statusCode field instead of status
  • Update toJSON method in StorageApiError class to return statusCode instead of status
  • Modify handleError function in src/lib/fetch.ts to handle statusCode instead of status

Additional context

Supabase Storage API scheme https://supabase.github.io/storage/

errorScheme {
  statusCode*	string
  error*	string
  message*	string
}

putcho01 avatar Nov 04 '24 10:11 putcho01

I believe this is not the problem about StorageError, which is handled and constructed by handleError in lib/fetch.ts.

The problem is that for some reasons upload APIs are not using these helper functions while others do. You can check my PR #216

hmpthz avatar Nov 21 '24 12:11 hmpthz

We've merged #216 which resolves this by making upload errors consistent with all other operations.

itslenny avatar May 16 '25 14:05 itslenny