> For the complete documentation index, see [llms.txt](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/extra-module-2-exception-filters/notfound-exception-filter.md).

# NotFound exception filter

An exception filter for entities that are not found.

Let's begin with the simpler case: when an entity is not found. To start, let's go back to the <mark style="color:blue;">`UsersService`</mark> and look at the <mark style="color:blue;">`findOne()`</mark> method. We may then replace the repository's <mark style="color:blue;">`findOne()`</mark> call with <mark style="color:blue;">`findOneOrFail()`</mark>. Now, instead of returning <mark style="color:blue;">null</mark>, an error will be thrown by TypeORM, the <mark style="color:blue;">`EntityNotFoundError`</mark>. When searching for a user that does not exist, we can then notice that an **Internal Server Error** exception is thrown.

Obviously, this exception is too generic. But we can **catch** the error to return something more appropriate, so we are well on our way. We want to automatically throw a <mark style="color:blue;">`NotFoundException`</mark> whenever this error occurs. And to achieve this, we'll use an **exception filter**.
