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, this.bucketName,
); );
try {
await this.client.makeBucket(this.bucketName); 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); 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( this.logger.log(
"A new storage bucket has been created and the policy has been applied successfully.", "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."); this.logger.log("Successfully connected to the storage service.");
} }
} catch (error) { } catch (error) {
throw new InternalServerErrorException( throw new InternalServerErrorException(error);
"There was an error while creating the storage bucket.",
);
} }
} }

View File

@ -137,7 +137,7 @@
"@nestjs/terminus": "^10.1.1", "@nestjs/terminus": "^10.1.1",
"@paralleldrive/cuid2": "^2.2.2", "@paralleldrive/cuid2": "^2.2.2",
"@pdf-lib/fontkit": "^1.1.1", "@pdf-lib/fontkit": "^1.1.1",
"@phosphor-icons/react": "^2.0.14", "@phosphor-icons/react": "^2.0.15",
"@prisma/client": "^5.6.0", "@prisma/client": "^5.6.0",
"@radix-ui/react-accordion": "^1.1.2", "@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-alert-dialog": "^1.0.5", "@radix-ui/react-alert-dialog": "^1.0.5",

8
pnpm-lock.yaml generated
View File

@ -78,8 +78,8 @@ dependencies:
specifier: ^1.1.1 specifier: ^1.1.1
version: 1.1.1 version: 1.1.1
'@phosphor-icons/react': '@phosphor-icons/react':
specifier: ^2.0.14 specifier: ^2.0.15
version: 2.0.14(react-dom@18.2.0)(react@18.2.0) version: 2.0.15(react-dom@18.2.0)(react@18.2.0)
'@prisma/client': '@prisma/client':
specifier: ^5.6.0 specifier: ^5.6.0
version: 5.6.0(prisma@5.6.0) version: 5.6.0(prisma@5.6.0)
@ -4420,8 +4420,8 @@ packages:
typescript: 5.3.2 typescript: 5.3.2
dev: true dev: true
/@phosphor-icons/react@2.0.14(react-dom@18.2.0)(react@18.2.0): /@phosphor-icons/react@2.0.15(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-VaZ7/JEQ7dW+Up23l7t6lqJ3dPJupM03916Pat+ZOLX1vex9OeX9t8RZLJWt0oVrdc/GcrAyRD5FESDeP+M4tQ==} resolution: {integrity: sha512-PQKNcRrfERlC8gJGNz0su0i9xVmeubXSNxucPcbCLDd9u0cwJVTEyYK87muul/svf0UXFdL2Vl6bbeOhT1Mwow==}
engines: {node: '>=10'} engines: {node: '>=10'}
peerDependencies: peerDependencies:
react: '>= 16.8' react: '>= 16.8'