# Error structure

To keep the same pattern as Nest when throwing an exception, let's have the fields <mark style="color:blue;">`statusCode`</mark> with the code of the status and <mark style="color:blue;">`error`</mark> with the name of this status. Let's then create the file <mark style="color:purple;">common</mark>/<mark style="color:purple;">util</mark>/<mark style="color:purple;">http-error.util</mark>. Here, we'll define <mark style="color:blue;">`status`</mark> and <mark style="color:blue;">`error`</mark> pairs to type the errors in a standard and safe way.

```typescript
export const HttpError = {
  NOT_FOUND: {
    status: HttpStatus.NOT_FOUND,
    error: 'Not Found',
  },
} as const;
```

To only allow errors in this format, we can create an interface...

```typescript
interface IHttpError {
  readonly status: HttpStatus;
  readonly error: string;
}
```

...to state that the <mark style="color:blue;">`HttpError`</mark> must follow its contract.

```typescript
satisfies Record<string, IHttpError>;
```

Going back to the filter, we can extract these two fields from the aproppriate error.

```typescript
const { status, error } = HttpError.NOT_FOUND;
```

The next step is to extract the entity name from the message.
