How to return a 404 HTTP status code when promise resolve to undefined in Nest?
问题 In order to avoid boilerplate code (checking for undefined in every controller, over and over again), how can I automatically return a 404 error when the promise in getOne returns undefined? @Controller('/customers') export class CustomerController { constructor ( @InjectRepository(Customer) private readonly repository: Repository<Customer> ) { } @Get('/:id') async getOne(@Param('id') id): Promise<Customer|undefined> { return this.repository.findOne(id) .then(result => { if (typeof result ===