I'm still discovering Nestjs and I can't understand how to return standard HTTP error.
For instance, in my controller, I have this endpoint defined (simplified for better readability):
@Post('login')
checkLogin(@Body() body, @Res() res: Response) {
this.loginService.checkLogin(body.login, body.password)
.then((response) => {
return response;
})
.catch(error => {
this.logger.log(`Access Denied: ${error}`)
throw new HttpException('Access Denied', HttpStatus.FORBIDDEN);
})
}
which calls the following service (with a bit of pseudo-code to keep it readable):
async checkLogin(login, password) {
if(login and password are correct) {
return Promise.resolve(user);
}
else {
const error_msg = 'Access Denied'
this.logger.log(error_msg);
return Promise.reject(new Error(error_msg));
}
}
When I test this endpoint with Postman, I get a socket hang up error and no proper response. The Nestjs logs show the thrown exception and that's it.
What am I missing? What am I doing wrong?
Thanks for any help.