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

Response error object other than the expected StorageError is returned. #273

Open
gonta1026 opened this issue Jan 29, 2023 · 6 comments
Open
Labels
bug Something isn't working

Comments

@gonta1026
Copy link

gonta1026 commented Jan 29, 2023

Bug report

Describe the bug

A non-StorageError response error object is returned.

To Reproduce

  const { error } = await supabase.storage.from(BUCKET.ITEM).upload(path, image.file, {
    upsert: true,
  })
  // expect: StorageError | null
  // but returned error : {statusCode: '400', error: 'Invalid Input', message: 'The object name contains invalid characters'}
  if (error instanceof StorageError) {
    // Not Reachable...
    console.log({ error })
  }
  1. upload image file
  2. return validation error (Because it contains Japanese strings)
  3. Error response returns with no expectation(example: {statusCode: '400', error: 'Invalid Input', message: 'The object name contains invalid characters'}

Expected behavior

Newly implement a response or expected response structure with a StorageError structure.

System information

  • OS: macOS m2
  • Browser chrome
  • Version of "@supabase/supabase-js": "^2.2.3",
  • Version of Node.js: v18.12.0
@gonta1026 gonta1026 added the bug Something isn't working label Jan 29, 2023
@gonta1026 gonta1026 changed the title StorageErrorではないレスポンスのエラーオブジェクトが返されてしまう。 A non-StorageError response error object is returned. Jan 29, 2023
@gonta1026 gonta1026 changed the title A non-StorageError response error object is returned. A response error object other than the expected StorageError is returned. Jan 29, 2023
@gonta1026 gonta1026 changed the title A response error object other than the expected StorageError is returned. Response error object other than the expected StorageError is returned. Jan 29, 2023
@Xuanwo
Copy link

Xuanwo commented May 2, 2023

Duplicated with #133

@groyGetaway
Copy link

This is not a duplicate of #133
This ticket is about the typescript object StorageError. The response received in "error" contains different members than the definition of StorageError.

I.e. the "error" member of the received payload is missing in StorageError.

@adamjjones
Copy link

I am having the same issue. I try to upload a file called css.png and it says 'The object name contains invalid characters'. Not sure if it's my policies on my bucket, but css.png is definitely valid.

@shalawfatah
Copy link

I'm having the same issue and it cripples my project as suddenly images are not uploaded.

@onalv
Copy link

onalv commented Oct 13, 2023

I've the same problem as the original author described. I think the other comments are not related to the original issue, this is just a error type problem.

@zhyd1997
Copy link

zhyd1997 commented Dec 8, 2023

/**
* Upload a new object to a storage
* @param request
* @param options
*/
async uploadNewObject(request: FastifyRequest, options: UploadObjectOptions) {
mustBeValidKey(options.objectName, 'The object name contains invalid characters')

/**
* Validates if a given object key is valid
* throws if invalid
* @param key
* @param message
*/
export function mustBeValidKey(key: string, message: string) {
if (!isValidKey(key)) {
throw new StorageBackendError('Invalid Input', 400, message)
}
}

/**
* Validates if a given object key or bucket key is valid
* @param key
*/
export function isValidKey(key: string): boolean {
// only allow s3 safe characters and characters which require special handling for now
// https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html
return key.length > 0 && /^(\w|\/|!|-|\.|\*|'|\(|\)| |&|\$|@|=|;|:|\+|,|\?)*$/.test(key)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants