π Bug Report: Uncaught Exception on Storage#createFile
jortuck opened this issue Β· 3 comments
π Reproduction steps
When trying to upload a file using a bad API key, an uncaught exception is thrown.
client.setEndpoint(endpoint)
client.setProjectprojectid)
client.setKey(badkey)
const storage = new sdk.Storage(client);
try {
const appFile = await storage.createFile("files",file.name,InputFile.fromPath(directory,file.name))
return true;
}catch (e){
console.log(e);
return false;
}
π Expected behavior
I should be able to catch the exception my self in my own try/catch block.
try {
const appFile = await storage.createFile("files",file.name,InputFile.fromPath(directory,file.name))
return true;
}catch (e){
console.log(e);
return false;
}
π Actual Behavior
It actually crashes the whole application, and spits out a stack trace.
C:\laragon\www\myfiles\node_modules\.pnpm\node-appwrite@8.1.0\node_modules\node-appwrite\lib\client.js:171
throw new AppwriteException(error.response.data.message, error.response.status, error.response.data.type, error.response.data);
^
AppwriteException [Error]: The current user is not authorized to perform the requested action.
at Client.call (C:\laragon\www\myfiles\node_modules\.pnpm\node-appwrite@8.1.0\node_modules\node-appwrite\lib\client.js:171:31)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async uploadChunk (C:\laragon\www\myfiles\node_modules\.pnpm\node-appwrite@8.1.0\node_modules\node-appwrite\lib\services\storage.js:371:24)
at async Writable.<anonymous> (C:\laragon\www\myfiles\node_modules\.pnpm\node-appwrite@8.1.0\node_modules\node-appwrite\lib\services\storage.js:433:21) {
code: 401,
type: 'user_unauthorized',
response: {
message: 'The current user is not authorized to perform the requested action.',
code: 401,
type: 'user_unauthorized',
version: '1.1.1'
}
}
Node.js v17.2.0
ELIFECYCLEβ Command failed with exit code 1.
β
π² Appwrite version
Version 1.1.1
π» Operating system
Windows
𧱠Your Environment
N/A
π Have you spent some time to check if this issue has been raised before?
- I checked and didn't find similar issue
π’ Have you read the Code of Conduct?
- I have read the Code of Conduct
Looks like we may have assumed this would catch any errors:
sdk-for-node/lib/services/storage.js
Lines 439 to 441 in 0fac3f6
I think the solution might be to add a try/catch here:
sdk-for-node/lib/services/storage.js
Lines 431 to 437 in 0fac3f6
like:
writeStream.on("finish", async () => {
if(currentChunkSize > 0) {
try {
await uploadChunk(true);
} catch (e) {
reject(e);
}
}
resolve(response);
});
@DriedSponge can we actually close this as a duplicate of #45 and you can ππΌ the previous issue?
@DriedSponge can we actually close this as a duplicate of #45 and you can ππΌ the previous issue?
Alright I'll go ahead and do that. Thanks!