HttpStatusEnhancer
File: 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
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)
setHttpStatusCode(httpStatusCode: number)
Sets the HTTP status code and validates it against known status codes.
Usage Example:
setUrl(url: string)
setUrl(url: string)
Sets the URL where the error occurred and validates its format.
Usage Example:
setHttpMethod(httpMethod: string)
setHttpMethod(httpMethod: string)
Sets the HTTP method used in the request and validates it against known methods.
Usage Example:
setRequestHeaders(headers: { [key: string]: any })
setRequestHeaders(headers: { [key: string]: any })
Sets the request headers.
Usage Example:
setResponseHeaders(headers: { [key: string]: any })
setResponseHeaders(headers: { [key: string]: any })
Sets the response headers.
Usage Example:
setQueryParams(params: { [key: string]: any })
setQueryParams(params: { [key: string]: any })
Sets the query parameters.
Usage Example:
setRequestBody(body: any)
setRequestBody(body: any)
Sets the body of the HTTP request.
Usage Example:
setResponseBody(body: any)
setResponseBody(body: any)
Sets the body of the HTTP response.
Usage Example:
setClientIp(ip: string)
setClientIp(ip: string)
Sets the client's IP address.
Usage Example:
setLatency(latency: number)
setLatency(latency: number)
Sets the latency of the request in milliseconds.
Usage Example: