fix: StorageError shape to match returned errors from API
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
StorageApiErrorclass insrc/lib/errors.tsto have astatusCodefield instead ofstatus - Update
toJSONmethod inStorageApiErrorclass to returnstatusCodeinstead ofstatus - Modify
handleErrorfunction insrc/lib/fetch.tsto handlestatusCodeinstead ofstatus
Additional context
Supabase Storage API scheme https://supabase.github.io/storage/
errorScheme {
statusCode* string
error* string
message* string
}
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
We've merged #216 which resolves this by making upload errors consistent with all other operations.