# HttpStatusEnhancer

*File:* [*`http-status.enhancer.ts`*](https://github.com/labrynx/error-enhanced/blob/main/src/lib/enhancers/http-status.enhancer.ts)

### Overview

The `HttpStatusEnhancer` class is designed to augment error objects with HTTP-specific metadata. This can be valuable for debugging, monitoring, and auditing HTTP-related issues within applications.

### Properties

| Property          | Description                                                     |
| ----------------- | --------------------------------------------------------------- |
| `httpStatusCode`  | HTTP Status Code, default is `-1`.                              |
| `url`             | URL where the error occurred, default is an empty string.       |
| `httpMethod`      | HTTP Method used (GET, POST, etc.), default is an empty string. |
| `requestHeaders`  | HTTP request headers, default is an empty object.               |
| `responseHeaders` | HTTP response headers, default is an empty object.              |
| `queryParams`     | Query parameters in the URL, default is an empty object.        |
| `requestBody`     | Body of the HTTP request, default is `null`.                    |
| `responseBody`    | Body of the HTTP response, default is `null`.                   |
| `clientIp`        | Client's IP address, default is an empty string.                |
| `latency`         | Latency in milliseconds, default is `-1`.                       |

### Methods

#### `setHttpStatusCode(httpStatusCode: number)`

Sets the HTTP status code and validates it against known status codes.

**Usage Example**:

```typescript
const httpStatus = new HttpStatusEnhancer();
httpStatus.setHttpStatusCode(200);
```

#### `setUrl(url: string)`

Sets the URL where the error occurred and validates its format.

**Usage Example**:

```typescript
httpStatus.setUrl("https://example.com");
```

#### `setHttpMethod(httpMethod: string)`

Sets the HTTP method used in the request and validates it against known methods.

**Usage Example**:

```typescript
httpStatus.setHttpMethod("GET");
```

#### `setRequestHeaders(headers: { [key: string]: any })`

Sets the request headers.

**Usage Example**:

```typescript
httpStatus.setRequestHeaders({ "Content-Type": "application/json" });
```

#### `setResponseHeaders(headers: { [key: string]: any })`

Sets the response headers.

**Usage Example**:

```typescript
httpStatus.setResponseHeaders({ "Content-Type": "application/json" });
```

#### `setQueryParams(params: { [key: string]: any })`

Sets the query parameters.

**Usage Example**:

```typescript
httpStatus.setQueryParams({ "page": 1, "limit": 10 });
```

#### `setRequestBody(body: any)`

Sets the body of the HTTP request.

**Usage Example**:

```typescript
httpStatus.setRequestBody({ "key": "value" });
```

#### `setResponseBody(body: any)`

Sets the body of the HTTP response.

**Usage Example**:

```typescript
httpStatus.setResponseBody({ "key": "value" });
```

#### `setClientIp(ip: string)`

Sets the client's IP address.

**Usage Example**:

```typescript
httpStatus.setClientIp("192.168.0.1");
```

#### `setLatency(latency: number)`

Sets the latency of the request in milliseconds.

**Usage Example**:

```typescript
httpStatus.setLatency(120);
```

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://labrynx.gitbook.io/error-enhanced/enhancers/httpstatusenhancer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
