Skip to content

Commit

Permalink
chore(api): add missing error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshPatel5940 committed May 23, 2024
1 parent 61e049b commit ce6d716
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion apps/api/src/provider/minio.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,16 @@ export const MinioProvider: Provider = {

async function createBucketIfNotExists() {
if (!minioClient) return
let bucketExists: boolean = false

const bucketExists = await minioClient.bucketExists(bucketName)
try {
bucketExists = await minioClient.bucketExists(bucketName)
} catch (error) {
logger.error('Error while checking if bucket exists in Minio', error)
throw new InternalServerErrorException(
'Error while checking if bucket exists in Minio'
)
}
if (!bucketExists) {
logger.warn(`Bucket ${bucketName} does not exist. Creating it.`)
try {
Expand All @@ -66,7 +74,9 @@ export const MinioProvider: Provider = {
if (!isServiceLoaded) {
return new InternalServerErrorException('Minio Client has not loaded')
}

const fileName = `${Date.now()}-${file.originalname}`

try {
await minioClient.putObject(
bucketName,
Expand All @@ -85,6 +95,7 @@ export const MinioProvider: Provider = {
if (!isServiceLoaded) {
return new InternalServerErrorException('Minio Client has not loaded')
}

try {
return await minioClient.presignedUrl('GET', bucketName, fileName)
} catch (error) {
Expand All @@ -99,8 +110,10 @@ export const MinioProvider: Provider = {
if (!isServiceLoaded) {
return new InternalServerErrorException('Minio Client has not loaded')
}

try {
await minioClient.removeObject(bucketName, fileName)
return true
} catch (error) {
logger.error('Error deleting file from Minio', error)
throw new InternalServerErrorException('Error deleting file from Minio')
Expand Down

0 comments on commit ce6d716

Please sign in to comment.