[英]How can I get rid of this error: error: unreported exception FileNotFoundException;
[英]How to I can custom exception message from FileInterceptor?
我想要 FileInterceptor 的自定義異常。
這是我的代碼行:
@Post('single')
@UseInterceptors(
FileInterceptor('file', { limits: {
files: 1
}}),
)
async uploadFile(@UploadedFile() file, @GetUser('id') userId: number, @Body() dto) {
this.logger.log('Upload file');
file.createdBy = userId;
file.oldFileName = dto.oldFileName;
return this.client.send('upload_file', file);
}
我傳入帶文件屬性的body,是1個數組文件(有2個文件)
我收到消息:
{
"response": {
"statusCode": 400,
"message": "Too many files",
"error": "Bad Request"
},
"status": 400,
"message": "Too many files",
"name": "BadRequestException"
}
我想要像這樣自定義該消息:
{
"code": 400,
"message": "Too many files"
}
請幫我一個解決方案。 謝謝
你可以試試 這個來自定義你的錯誤
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.