fix: throw appropriate errors when connecting to storage bucket, closes #1561

This commit is contained in:
Amruth Pillai
2023-11-23 09:01:25 +01:00
parent d7abd74af3
commit a661076686
3 changed files with 21 additions and 10 deletions

View File

@ -67,8 +67,21 @@ export class StorageService implements OnModuleInit {
this.bucketName,
);
await this.client.makeBucket(this.bucketName);
await this.client.setBucketPolicy(this.bucketName, bucketPolicy);
try {
await this.client.makeBucket(this.bucketName);
} catch (error) {
throw new InternalServerErrorException(
"There was an error while creating the storage bucket.",
);
}
try {
await this.client.setBucketPolicy(this.bucketName, bucketPolicy);
} catch (error) {
throw new InternalServerErrorException(
"There was an error while applying the policy to the storage bucket.",
);
}
this.logger.log(
"A new storage bucket has been created and the policy has been applied successfully.",
@ -77,9 +90,7 @@ export class StorageService implements OnModuleInit {
this.logger.log("Successfully connected to the storage service.");
}
} catch (error) {
throw new InternalServerErrorException(
"There was an error while creating the storage bucket.",
);
throw new InternalServerErrorException(error);
}
}