Skip to content

Commit 4e10a8c

Browse files
authored
fix: Correct status code and message returned on invalid file upload (#700)
* fix: Correct status code and message returned on invalid file upload * Revert "fix: Correct status code and message returned on invalid file upload" This reverts commit f01a714. * Address comments
1 parent 569b7d9 commit 4e10a8c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

apps/api/src/common/files.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import path from 'path'
2+
import { UnsupportedMediaTypeException } from '@nestjs/common'
23

34
interface File {
45
fieldname: string
@@ -34,7 +35,7 @@ export function validateFileType(
3435
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
3536
]
3637
if (!mimeAllowlist.includes(file.mimetype)) {
37-
return cb(new Error('File mime type is not allowed'), false)
38+
return cb(new UnsupportedMediaTypeException('File mime type is not allowed'), false)
3839
}
3940

4041
const allowedExtensions = /txt|json|pdf|jpeg|jpg|png|xml|xlsx|xls|docx/
@@ -47,7 +48,10 @@ export function validateFileType(
4748
}
4849
const isExtensionSupported = allowedExtensions.test(ext)
4950
if (!isExtensionSupported) {
50-
return cb(new Error('File extension is not allowed: ' + file.filename), false)
51+
return cb(
52+
new UnsupportedMediaTypeException('File extension is not allowed: ' + file.filename),
53+
false,
54+
)
5155
}
5256

5357
cb(null, true)

0 commit comments

Comments
 (0)