'response to the client based on certain condition in Loopbackjs?
I am new to loopback4 and I am in learning phase. And I have issue with auto-generated api which always return response that defined on decorator or something failed they return 500 (Internal Server Error). I want to return for-example 400(badRequest) in the else block. How to ? I already tried many things but I did'nt. If anyone know how to handle it. Please let me know. Thanks
@del('/dctypes/{id}')
@response(204, {
description: 'Dctypes DELETE success',
})
async deleteById(@param.path.number('id') id: number): Promise<void> {
console.log(await this.dctypesRepository.alreadyInUser(id));
if ((await this.dctypesRepository.alreadyInUser(id)) === true) {
await this.dctypesRepository.deleteById(id);
// here I want to send 400(badRequest on this condition.
} else response(400, {description: 'This is custom made error.'});
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
