As a user I should be able to know when retrieveClientToken failed for a specific reason. See the following example:
constjsonResponse=awaithandleUpload({
body,
request,onBeforeGenerateToken: async(pathname: string,/* clientPayload?: string, */)=>{// Generate a client token for the browser to upload the file// ⚠️ Authenticate users before generating the token.// Otherwise, you're allowing anonymous uploads.constprofile=awaitgetCurrentProfile();if(!profile){console.log('User is not logged in');thrownewError('Not authenticated');}if(!userAccessControl.canUser(profile).createOwn(Resources.UPLOADS).granted){console.log('User does not have permission to upload files');thrownewError('You do not have permission to upload files');}return{allowedContentTypes: ['application/pdf','text/plain'],maximumSizeInBytes: 8_000_000,tokenPayload: JSON.stringify({profileId: profile.id})};},onUploadCompleted: async({ blob, tokenPayload })=>{// ...}});Assuming the above is set up in a route to handle uploads, I should receive 'You do not have permission to upload files' when the user is authenticated but not permitted to perform uploads, instead of the current 'Failed to retrieve the client token' error.
It seems the library is already set up to return the error in the body to the client, so we could attempt to parse the body for the error message.
As a user I should be able to know when
retrieveClientTokenfailed for a specific reason. See the following example:Assuming the above is set up in a route to handle uploads, I should receive 'You do not have permission to upload files' when the user is authenticated but not permitted to perform uploads, instead of the current 'Failed to retrieve the client token' error.
It seems the library is already set up to return the error in the body to the client, so we could attempt to parse the body for the error message.