<commit_before># Throw HTTP Exceptions

You can use [@tsed/exceptions](/docs/exceptions.md) or similar module to throw an http exception.
All exception will be intercepted by the [Global error handler](/docs/middlewares/override/global-error-handler.md)
and are sent to the client.

Here an example:

<<< @/docs/docs/snippets/controllers/response-throw-exceptions.ts

::: tip
This example will produce a response with status code 400 and "Not a number" message. 
`GlobalErrorHandlerMiddleware` will catch and format the error before sending it to the client.
:::

## Create custom exception

It also possible to create your own exception from any Exception of [@tsed/exceptions](/docs/exceptions.md)  and customize the response headers.

```typescript
import {BadRequest} from "@tsed/exceptions";
import {IResponseError} from "@tsed/common";

export class RequiredUserName extends BadRequest implements IResponseError {
    headers = {};
    errors = [];

    constructor() {
        super("The name is required");
        this.headers["my-custom-header"] = "value";

        // you can also specify errors field for functional errors (like AJV validation).
        this.errors.push({
             dataPath: "",
             keyword: "required",
             message: "should have required property 'name'",
             modelName: "User",
             params: {
               missingProperty: "name"
             },<commit_msg>docs: fix typos on http exceptions<commit_after># Throw HTTP Exceptions

You can use [@tsed/exceptions](/docs/exceptions.md) or similar module to throw an http exception.
All exceptions will be intercepted by the [Global error handler](/docs/middlewares/override/global-error-handler.md)
and are sent to the client.

Here is an example:

<<< @/docs/docs/snippets/controllers/response-throw-exceptions.ts

::: tip
This example will produce a response with status code 400 and "Not a number" message. 
`GlobalErrorHandlerMiddleware` will catch and format the error before sending it to the client.
:::

## Create custom exception

It is also possible to create your own exception from any Exception of [@tsed/exceptions](/docs/exceptions.md) and customize the response headers.

```typescript
import {BadRequest} from "@tsed/exceptions";
import {IResponseError} from "@tsed/common";

export class RequiredUserName extends BadRequest implements IResponseError {
    headers = {};
    errors = [];

    constructor() {
        super("The name is required");
        this.headers["my-custom-header"] = "value";

        // you can also specify errors field for functional errors (like AJV validation).
        this.errors.push({
             dataPath: "",
             keyword: "required",
             message: "should have required property 'name'",
             modelName: "User",
             params: {
               missingProperty: "name"
             },
{'fraction_non_alphanumeric': 0.09878682842287695, 'fraction_numerical': 0.0020797227036395147, 'mean_word_length': 3.2131386861313866, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6801226', 'n_tokens_mistral': 761, 'n_tokens_neox': 738, 'n_words': 283}