title: Decorator to return a 404 in a Nest controller
body: <p>I'm working on a backend using NestJS, (which is amazing btw). I have a 'standard get a single instance of an entity situation' similar to this example below.</p>
  
  <pre><code>@Controller('user')
  export class UserController {
      constructor(private readonly userService: UserService) {}
      ..
      ..
      ..
      @Get(':id')
      async findOneById(@Param() params): Promise&lt;User&gt; {
          return userService.findOneById(params.id);
      }
  </code></pre>
  
  <p>This is incredibly simple and works - however, if the user does not exist, the service returns undefined and the controller returns a 200 status code and an empty response.</p>
  
  <p>In order to make the controller return a 404, I came up with the following:</p>
  
  <pre><code>    @Get(':id')
      async findOneById(@Res() res, @Param() params): Promise&lt;User&gt; {
          const user: User = await this.userService.findOneById(params.id);
          if (user === undefined) {
              res.status(HttpStatus.NOT_FOUND).send();
          }
          else {
              res.status(HttpStatus.OK).json(user).send();
          }
      }
      ..
      ..
  </code></pre>
  
  <p>This works, but is a lot more code-y (yes it can be refactored).</p>
  
  <p>This could really use a decorator to handle this situation:</p>
  
  <pre><code>    @Get(':id')
      @OnUndefined(404)
      async findOneById(@Param() params): Promise&lt;User&gt; {
          return userService.findOneById(params.id);
      }
  </code></pre>
  
  <p>Anyone aware of a decorator that does this, or a better solution than the one above?</p>