@fishka/express 0.9.6 → 0.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,7 +38,7 @@ exports.mount = mount;
38
38
  const assertions_1 = require("@fishka/assertions");
39
39
  const url = __importStar(require("url"));
40
40
  const api_types_1 = require("./api.types");
41
- const http_types_1 = require("./http.types");
41
+ const http_status_codes_1 = require("./http-status-codes");
42
42
  const error_handling_1 = require("./error-handling");
43
43
  const thread_local_storage_1 = require("./thread-local/thread-local-storage");
44
44
  const conversion_utils_1 = require("./utils/conversion.utils");
@@ -103,7 +103,7 @@ function createRouteHandler(method, endpoint) {
103
103
  if (tls?.requestId) {
104
104
  response.requestId = tls.requestId;
105
105
  }
106
- response.status = response.status || http_types_1.OK_STATUS;
106
+ response.status = response.status || http_status_codes_1.HTTP_OK;
107
107
  res.status(response.status);
108
108
  res.send(response);
109
109
  };
@@ -119,12 +119,12 @@ function validateUrlParameters(req, { $path, $query, }) {
119
119
  // Run Global Validation if registered.
120
120
  const globalValidator = api_types_1.URL_PARAMETER_INFO[key]?.validator;
121
121
  if (globalValidator) {
122
- (0, assertions_1.callValueAssertion)(value, globalValidator, `${http_types_1.BAD_REQUEST_STATUS}`);
122
+ (0, assertions_1.callValueAssertion)(value, globalValidator, `${http_status_codes_1.HTTP_BAD_REQUEST}`);
123
123
  }
124
124
  // Run Local Validation.
125
125
  const validator = $path?.[key];
126
126
  if (validator) {
127
- (0, assertions_1.callValueAssertion)(value, validator, `${http_types_1.BAD_REQUEST_STATUS}`);
127
+ (0, assertions_1.callValueAssertion)(value, validator, `${http_status_codes_1.HTTP_BAD_REQUEST}`);
128
128
  }
129
129
  }
130
130
  const parsedUrl = url.parse(req.url, true);
@@ -136,16 +136,16 @@ function validateUrlParameters(req, { $path, $query, }) {
136
136
  // Query params can be string | string[] | undefined. Global validators usually expect string.
137
137
  // We only validate if it's a single value or handle array in validator.
138
138
  // For simplicity, we pass value as is (unknown) to assertion.
139
- (0, assertions_1.callValueAssertion)(value, globalValidator, `${http_types_1.BAD_REQUEST_STATUS}`);
139
+ (0, assertions_1.callValueAssertion)(value, globalValidator, `${http_status_codes_1.HTTP_BAD_REQUEST}`);
140
140
  }
141
141
  const validator = $query?.[key];
142
142
  if (validator) {
143
- (0, assertions_1.callValueAssertion)(value, validator, `${http_types_1.BAD_REQUEST_STATUS}`);
143
+ (0, assertions_1.callValueAssertion)(value, validator, `${http_status_codes_1.HTTP_BAD_REQUEST}`);
144
144
  }
145
145
  }
146
146
  }
147
147
  catch (error) {
148
- throw new api_types_1.HttpError(http_types_1.BAD_REQUEST_STATUS, (0, assertions_1.getMessageFromError)(error));
148
+ throw new api_types_1.HttpError(http_status_codes_1.HTTP_BAD_REQUEST, (0, assertions_1.getMessageFromError)(error));
149
149
  }
150
150
  }
151
151
  /**
@@ -178,23 +178,23 @@ async function executeBodyEndpoint(route, req, res) {
178
178
  // Handle validation based on whether validator is an object or function
179
179
  if (typeof validator === 'function') {
180
180
  // It's a ValueAssertion (function)
181
- (0, assertions_1.callValueAssertion)(apiRequest, validator, `${http_types_1.BAD_REQUEST_STATUS}: request body`);
181
+ (0, assertions_1.callValueAssertion)(apiRequest, validator, `${http_status_codes_1.HTTP_BAD_REQUEST}: request body`);
182
182
  }
183
183
  else {
184
184
  // It's an ObjectAssertion - use validateObject
185
185
  // We strictly assume it is an object because of the type definition (function | object)
186
186
  const objectValidator = validator;
187
187
  const isEmptyValidator = Object.keys(objectValidator).length === 0;
188
- const error = (0, assertions_1.validateObject)(apiRequest, objectValidator, `${http_types_1.BAD_REQUEST_STATUS}: request body`, {
188
+ const errorMessage = (0, assertions_1.validateObject)(apiRequest, objectValidator, `${http_status_codes_1.HTTP_BAD_REQUEST}: request body`, {
189
189
  failOnUnknownFields: !isEmptyValidator,
190
190
  });
191
- (0, assertions_1.assertTruthy)(!error, error);
191
+ (0, api_types_1.assertHttp)(!errorMessage, http_status_codes_1.HTTP_BAD_REQUEST, errorMessage || 'Request body validation failed');
192
192
  }
193
193
  }
194
194
  catch (error) {
195
195
  if (error instanceof api_types_1.HttpError)
196
196
  throw error;
197
- throw new api_types_1.HttpError(http_types_1.BAD_REQUEST_STATUS, (0, assertions_1.getMessageFromError)(error));
197
+ throw new api_types_1.HttpError(http_status_codes_1.HTTP_BAD_REQUEST, (0, assertions_1.getMessageFromError)(error));
198
198
  }
199
199
  const requestContext = newRequestContext(apiRequest, req, res);
200
200
  validateUrlParameters(req, { $path: route.$path, $query: route.$query });
@@ -5,6 +5,38 @@ export declare class HttpError extends Error {
5
5
  readonly details?: Record<string, unknown> | undefined;
6
6
  constructor(status: number, message: string, details?: Record<string, unknown> | undefined);
7
7
  }
8
+ /**
9
+ * Asserts that a condition is true, throwing an HttpError with the specified status code if false.
10
+ * This function is designed for HTTP-specific validation where you want to throw appropriate HTTP status codes.
11
+ *
12
+ * @param condition - The condition to check. If false, an HttpError will be thrown.
13
+ * @param status - The HTTP status code to use in the HttpError (e.g., 400 for Bad Request, 404 for Not Found).
14
+ * @param message - The error message to include in the HttpError.
15
+ *
16
+ * @throws {HttpError} If the condition is false, throws an HttpError with the specified status and message.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // Validate required parameter
21
+ * assertHttp(typeof userId === 'string', HTTP_BAD_REQUEST, 'User ID must be a string');
22
+ *
23
+ * // Validate resource existence
24
+ * assertHttp(user !== null, HTTP_NOT_FOUND, 'User not found');
25
+ *
26
+ * // Validate authorization
27
+ * assertHttp(user.isAdmin, HTTP_FORBIDDEN, 'Admin access required');
28
+ *
29
+ * // Validate authentication
30
+ * assertHttp(req.headers.authorization, HTTP_UNAUTHORIZED, 'Authorization header required');
31
+ * ```
32
+ *
33
+ * @see {@link HttpError}
34
+ * @see {@link HTTP_BAD_REQUEST}
35
+ * @see {@link HTTP_NOT_FOUND}
36
+ * @see {@link HTTP_FORBIDDEN}
37
+ * @see {@link HTTP_UNAUTHORIZED}
38
+ */
39
+ export declare function assertHttp(condition: boolean, status: number, message: string): void;
8
40
  export interface ApiResponse<ResponseEntity = unknown> {
9
41
  /** Result of the call. A single entity for non-paginated ${by-id} requests or an array for list queries. */
10
42
  result: ResponseEntity;
@@ -1,13 +1,48 @@
1
1
  import { assertString, assertTruthy } from '@fishka/assertions';
2
+ import { HTTP_BAD_REQUEST } from './http-status-codes';
2
3
  export class HttpError extends Error {
3
4
  constructor(status, message, details) {
4
5
  super(message);
5
6
  this.status = status;
6
7
  this.details = details;
7
- // Restore prototype chain for instanceof checks
8
+ // Restore the prototype chain for instanceof checks.
8
9
  Object.setPrototypeOf(this, HttpError.prototype);
9
10
  }
10
11
  }
12
+ /**
13
+ * Asserts that a condition is true, throwing an HttpError with the specified status code if false.
14
+ * This function is designed for HTTP-specific validation where you want to throw appropriate HTTP status codes.
15
+ *
16
+ * @param condition - The condition to check. If false, an HttpError will be thrown.
17
+ * @param status - The HTTP status code to use in the HttpError (e.g., 400 for Bad Request, 404 for Not Found).
18
+ * @param message - The error message to include in the HttpError.
19
+ *
20
+ * @throws {HttpError} If the condition is false, throws an HttpError with the specified status and message.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * // Validate required parameter
25
+ * assertHttp(typeof userId === 'string', HTTP_BAD_REQUEST, 'User ID must be a string');
26
+ *
27
+ * // Validate resource existence
28
+ * assertHttp(user !== null, HTTP_NOT_FOUND, 'User not found');
29
+ *
30
+ * // Validate authorization
31
+ * assertHttp(user.isAdmin, HTTP_FORBIDDEN, 'Admin access required');
32
+ *
33
+ * // Validate authentication
34
+ * assertHttp(req.headers.authorization, HTTP_UNAUTHORIZED, 'Authorization header required');
35
+ * ```
36
+ *
37
+ * @see {@link HttpError}
38
+ * @see {@link HTTP_BAD_REQUEST}
39
+ * @see {@link HTTP_NOT_FOUND}
40
+ * @see {@link HTTP_FORBIDDEN}
41
+ * @see {@link HTTP_UNAUTHORIZED}
42
+ */
43
+ export function assertHttp(condition, status, message) {
44
+ assertTruthy(condition, () => new HttpError(status, message));
45
+ }
11
46
  /** Converts an API response value into a standardized ApiResponse structure. */
12
47
  export function response(result) {
13
48
  return { result };
@@ -27,5 +62,5 @@ export function registerUrlParameter(name, info) {
27
62
  */
28
63
  export function assertUrlParameter(name) {
29
64
  assertString(name, 'Url parameter name must be a string');
30
- assertTruthy(URL_PARAMETER_INFO[name], `Invalid URL parameter: '${name}'. Please register it using 'registerUrlParameter('${name}', ...)'`);
65
+ assertHttp(URL_PARAMETER_INFO[name] !== undefined, HTTP_BAD_REQUEST, `Invalid URL parameter: '${name}'. Please register it using 'registerUrlParameter('${name}', ...)'`);
31
66
  }
@@ -1,5 +1,5 @@
1
1
  import { HttpError } from '../api.types';
2
- import { UNAUTHORIZED_STATUS } from '../http.types';
2
+ import { HTTP_UNAUTHORIZED } from '../http-status-codes';
3
3
  /**
4
4
  * Basic authentication strategy using username/password validation.
5
5
  * Parses HTTP Basic Authorization header and validates credentials.
@@ -51,7 +51,7 @@ export class BasicAuthStrategy {
51
51
  async validateCredentials({ username, password }) {
52
52
  const user = await this.verifyFn(username, password);
53
53
  if (!user) {
54
- throw new HttpError(UNAUTHORIZED_STATUS, 'Invalid username or password');
54
+ throw new HttpError(HTTP_UNAUTHORIZED, 'Invalid username or password');
55
55
  }
56
56
  return user;
57
57
  }
@@ -1,5 +1,5 @@
1
1
  import { HttpError } from '../api.types';
2
- import { UNAUTHORIZED_STATUS } from '../http.types';
2
+ import { HTTP_UNAUTHORIZED } from '../http-status-codes';
3
3
  /**
4
4
  * Creates a middleware that enforces authentication using the provided strategy.
5
5
  * The authenticated user is stored in the context under the 'authUser' key.
@@ -16,7 +16,7 @@ export function createAuthMiddleware(strategy, onSuccess) {
16
16
  // If no credentials found (and strategy returned undefined), we must deny access here.
17
17
  // In a composite strategy scenario, we might want to try the next strategy, but this helper is for a single strategy enforcement.
18
18
  if (!credentials) {
19
- throw new HttpError(UNAUTHORIZED_STATUS, 'No credentials provided or invalid format');
19
+ throw new HttpError(HTTP_UNAUTHORIZED, 'No credentials provided or invalid format');
20
20
  }
21
21
  // Validate credentials and get authenticated user
22
22
  const user = await strategy.validateCredentials(credentials);
@@ -42,7 +42,7 @@ export function createAuthMiddleware(strategy, onSuccess) {
42
42
  export function getAuthUser(context) {
43
43
  const user = context.authUser;
44
44
  if (!user) {
45
- throw new HttpError(UNAUTHORIZED_STATUS, 'User not found in context. Did you add auth middleware?');
45
+ throw new HttpError(HTTP_UNAUTHORIZED, 'User not found in context. Did you add auth middleware?');
46
46
  }
47
47
  return user;
48
48
  }
@@ -1,5 +1,5 @@
1
1
  import { HttpError } from '../api.types';
2
- import { UNAUTHORIZED_STATUS } from '../http.types';
2
+ import { HTTP_UNAUTHORIZED } from '../http-status-codes';
3
3
  /**
4
4
  * Bearer authentication strategy (commonly used for JWTs).
5
5
  * Extracts the token from the 'Authorization: Bearer <token>' header.
@@ -48,7 +48,7 @@ export class BearerAuthStrategy {
48
48
  async validateCredentials(token) {
49
49
  const user = await this.verifyFn(token);
50
50
  if (!user) {
51
- throw new HttpError(UNAUTHORIZED_STATUS, 'Invalid token');
51
+ throw new HttpError(HTTP_UNAUTHORIZED, 'Invalid token');
52
52
  }
53
53
  return user;
54
54
  }
@@ -1,6 +1,6 @@
1
1
  import { getMessageFromError } from '@fishka/assertions';
2
2
  import { HttpError } from './api.types';
3
- import { BAD_REQUEST_STATUS, INTERNAL_ERROR_STATUS } from './http.types';
3
+ import { HTTP_BAD_REQUEST, HTTP_INTERNAL_SERVER_ERROR } from './http-status-codes';
4
4
  import { getRequestLocalStorage } from './thread-local/thread-local-storage';
5
5
  import { wrapAsApiResponse } from './utils/conversion.utils';
6
6
  function buildApiResponse(error) {
@@ -20,7 +20,7 @@ function buildApiResponse(error) {
20
20
  response = {
21
21
  ...wrapAsApiResponse(undefined),
22
22
  error: errorMessage && errorMessage.length > 0 ? errorMessage : 'Internal error',
23
- status: INTERNAL_ERROR_STATUS,
23
+ status: HTTP_INTERNAL_SERVER_ERROR,
24
24
  };
25
25
  }
26
26
  if (requestId) {
@@ -36,7 +36,7 @@ export function catchRouteErrors(fn) {
36
36
  }
37
37
  catch (error) {
38
38
  const apiResponse = buildApiResponse(error);
39
- if (apiResponse.status >= INTERNAL_ERROR_STATUS) {
39
+ if (apiResponse.status >= HTTP_INTERNAL_SERVER_ERROR) {
40
40
  console.error(`catchRouteErrors: ${req.path}`, error);
41
41
  }
42
42
  else {
@@ -59,7 +59,7 @@ export async function catchAllMiddleware(error, _, res, next) {
59
59
  // Report as critical. This kind of error should never happen.
60
60
  console.error('catchAllMiddleware:', getMessageFromError(error));
61
61
  const apiResponse = error instanceof SyntaxError // JSON body parsing error.
62
- ? buildApiResponse(`${BAD_REQUEST_STATUS}: Failed to parse request: ${error.message}`)
62
+ ? buildApiResponse(`${HTTP_BAD_REQUEST}: Failed to parse request: ${error.message}`)
63
63
  : buildApiResponse(error);
64
64
  res.status(apiResponse.status);
65
65
  res.send(apiResponse);
@@ -0,0 +1,179 @@
1
+ /** The request has succeeded (200) */
2
+ export declare const HTTP_OK = 200;
3
+ /** The request has been fulfilled, and a new resource is created (201) */
4
+ export declare const HTTP_CREATED = 201;
5
+ /** The request has been accepted for processing, but the processing is not yet complete (202) */
6
+ export declare const HTTP_ACCEPTED = 202;
7
+ /** The server successfully processed the request, and is not returning any content (204) */
8
+ export declare const HTTP_NO_CONTENT = 204;
9
+ /** The request has been successfully processed, but is returning no content (205) */
10
+ export declare const HTTP_RESET_CONTENT = 205;
11
+ /** The server is delivering only part of the resource due to a range header sent by the client (206) */
12
+ export declare const HTTP_PARTIAL_CONTENT = 206;
13
+ /** The IM used the server processed a request successfully, but the response is transformed (226) */
14
+ export declare const HTTP_IM_USED = 226;
15
+ /** The resource has been moved permanently to a new URL (301) */
16
+ export declare const HTTP_MOVED_PERMANENTLY = 301;
17
+ /** The resource is available at a different URL (302) */
18
+ export declare const HTTP_FOUND = 302;
19
+ /** The resource has not been modified since the last request (304) */
20
+ export declare const HTTP_NOT_MODIFIED = 304;
21
+ /** The server could not understand the request due to invalid syntax (400) */
22
+ export declare const HTTP_BAD_REQUEST = 400;
23
+ /** The client must authenticate itself to get the requested response (401) */
24
+ export declare const HTTP_UNAUTHORIZED = 401;
25
+ /** The client does not have access rights to the content (403) */
26
+ export declare const HTTP_FORBIDDEN = 403;
27
+ /** The server cannot find the requested resource (404) */
28
+ export declare const HTTP_NOT_FOUND = 404;
29
+ /** The request method is known by the server but is not supported by the target resource (405) */
30
+ export declare const HTTP_METHOD_NOT_ALLOWED = 405;
31
+ /** The client must authenticate using a proxy (407) */
32
+ export declare const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407;
33
+ /** The server timed out waiting for the request (408) */
34
+ export declare const HTTP_REQUEST_TIMEOUT = 408;
35
+ /** The request conflicts with the current state of the server (409) */
36
+ export declare const HTTP_CONFLICT = 409;
37
+ /** The resource requested is no longer available and will not be available again (410) */
38
+ export declare const HTTP_GONE = 410;
39
+ /** The request does not meet the preconditions that the server requires (412) */
40
+ export declare const HTTP_PRECONDITION_FAILED = 412;
41
+ /** The client sent a request that is too large for the server to process (413) */
42
+ export declare const HTTP_PAYLOAD_TOO_LARGE = 413;
43
+ /** The URI requested by the client is too long for the server to process (414) */
44
+ export declare const HTTP_URI_TOO_LONG = 414;
45
+ /** The media format of the requested data is not supported by the server (415) */
46
+ export declare const HTTP_UNSUPPORTED_MEDIA_TYPE = 415;
47
+ /** The range specified by the client cannot be fulfilled (416) */
48
+ export declare const HTTP_RANGE_NOT_SATISFIABLE = 416;
49
+ /** The expectation given in the request header could not be met by the server (417) */
50
+ export declare const HTTP_EXPECTATION_FAILED = 417;
51
+ /** The server refuses to brew coffee because it is a teapot (418) - an Easter egg from RFC 2324 */
52
+ export declare const HTTP_IM_A_TEAPOT = 418;
53
+ /** The request was well-formed but was unable to be followed due to semantic errors (422) */
54
+ export declare const HTTP_UNPROCESSABLE_ENTITY = 422;
55
+ /** The resource that is being accessed is locked (423) */
56
+ export declare const HTTP_LOCKED = 423;
57
+ /** The resource requested is dependent on another resource that has failed (424) */
58
+ export declare const HTTP_FAILED_DEPENDENCY = 424;
59
+ /** The server is unwilling to risk processing a request that might be replayed (425) */
60
+ export declare const HTTP_TOO_EARLY = 425;
61
+ /** The client needs to upgrade its protocol (426) */
62
+ export declare const HTTP_UPGRADE_REQUIRED = 426;
63
+ /** The server requires the request to be conditional (428) */
64
+ export declare const HTTP_PRECONDITION_REQUIRED = 428;
65
+ /** The client has sent too many requests in a given amount of time (429) */
66
+ export declare const HTTP_TOO_MANY_REQUESTS = 429;
67
+ /** The request header fields are too large (431) */
68
+ export declare const HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
69
+ /** The client closed the connection with the server before the request was completed (444) */
70
+ export declare const HTTP_CONNECTION_CLOSED_WITHOUT_RESPONSE = 444;
71
+ /** The client requested an unavailable legal action (451) */
72
+ export declare const HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451;
73
+ /** The server encountered an internal error and was unable to complete the request (500) */
74
+ export declare const HTTP_INTERNAL_SERVER_ERROR = 500;
75
+ /** The request method is not supported by the server and cannot be handled (501) */
76
+ export declare const HTTP_NOT_IMPLEMENTED = 501;
77
+ /** The server, while acting as a gateway or proxy, received an invalid response from the upstream server (502) */
78
+ export declare const HTTP_BAD_GATEWAY = 502;
79
+ /** The server is not ready to handle the request, typically due to temporary overload or maintenance (503) */
80
+ export declare const HTTP_SERVICE_UNAVAILABLE = 503;
81
+ /** The server, while acting as a gateway or proxy, did not get a response in time from the upstream server (504) */
82
+ export declare const HTTP_GATEWAY_TIMEOUT = 504;
83
+ /**
84
+ * An object containing common HTTP status codes.
85
+ * These constants can be used to improve code readability and maintainability.
86
+ * @deprecated Use individual HTTP_* constants for better tree-shaking
87
+ */
88
+ export declare const HttpStatusCode: {
89
+ /** The request has succeeded (200) */
90
+ OK: number;
91
+ /** The request has been fulfilled, and a new resource is created (201) */
92
+ CREATED: number;
93
+ /** The request has been accepted for processing, but the processing is not yet complete (202) */
94
+ ACCEPTED: number;
95
+ /** The server successfully processed the request, and is not returning any content (204) */
96
+ NO_CONTENT: number;
97
+ /** The request has been successfully processed, but is returning no content (205) */
98
+ RESET_CONTENT: number;
99
+ /** The server is delivering only part of the resource due to a range header sent by the client (206) */
100
+ PARTIAL_CONTENT: number;
101
+ /** The IM used the server processed a request successfully, but the response is transformed (226) */
102
+ IM_USED: number;
103
+ /** The resource has been moved permanently to a new URL (301) */
104
+ MOVED_PERMANENTLY: number;
105
+ /** The resource is available at a different URL (302) */
106
+ FOUND: number;
107
+ /** The resource has not been modified since the last request (304) */
108
+ NOT_MODIFIED: number;
109
+ /** The server could not understand the request due to invalid syntax (400) */
110
+ BAD_REQUEST: number;
111
+ /** The client must authenticate itself to get the requested response (401) */
112
+ UNAUTHORIZED: number;
113
+ /** The client does not have access rights to the content (403) */
114
+ FORBIDDEN: number;
115
+ /** The server cannot find the requested resource (404) */
116
+ NOT_FOUND: number;
117
+ /** The request method is known by the server but is not supported by the target resource (405) */
118
+ METHOD_NOT_ALLOWED: number;
119
+ /** The client must authenticate using a proxy (407) */
120
+ PROXY_AUTHENTICATION_REQUIRED: number;
121
+ /** The server timed out waiting for the request (408) */
122
+ REQUEST_TIMEOUT: number;
123
+ /** The request conflicts with the current state of the server (409) */
124
+ CONFLICT: number;
125
+ /** The resource requested is no longer available and will not be available again (410) */
126
+ GONE: number;
127
+ /** The request does not meet the preconditions that the server requires (412) */
128
+ PRECONDITION_FAILED: number;
129
+ /** The client sent a request that is too large for the server to process (413) */
130
+ PAYLOAD_TOO_LARGE: number;
131
+ /** The URI requested by the client is too long for the server to process (414) */
132
+ URI_TOO_LONG: number;
133
+ /** The media format of the requested data is not supported by the server (415) */
134
+ UNSUPPORTED_MEDIA_TYPE: number;
135
+ /** The range specified by the client cannot be fulfilled (416) */
136
+ RANGE_NOT_SATISFIABLE: number;
137
+ /** The expectation given in the request header could not be met by the server (417) */
138
+ EXPECTATION_FAILED: number;
139
+ /** The server refuses to brew coffee because it is a teapot (418) - an Easter egg from RFC 2324 */
140
+ IM_A_TEAPOT: number;
141
+ /** The request was well-formed but was unable to be followed due to semantic errors (422) */
142
+ UNPROCESSABLE_ENTITY: number;
143
+ /** The resource that is being accessed is locked (423) */
144
+ LOCKED: number;
145
+ /** The resource requested is dependent on another resource that has failed (424) */
146
+ FAILED_DEPENDENCY: number;
147
+ /** The server is unwilling to risk processing a request that might be replayed (425) */
148
+ TOO_EARLY: number;
149
+ /** The client needs to upgrade its protocol (426) */
150
+ UPGRADE_REQUIRED: number;
151
+ /** The server requires the request to be conditional (428) */
152
+ PRECONDITION_REQUIRED: number;
153
+ /** The client has sent too many requests in a given amount of time (429) */
154
+ TOO_MANY_REQUESTS: number;
155
+ /** The request header fields are too large (431) */
156
+ REQUEST_HEADER_FIELDS_TOO_LARGE: number;
157
+ /** The client closed the connection with the server before the request was completed (444) */
158
+ CONNECTION_CLOSED_WITHOUT_RESPONSE: number;
159
+ /** The client requested an unavailable legal action (451) */
160
+ UNAVAILABLE_FOR_LEGAL_REASONS: number;
161
+ /** The server encountered an internal error and was unable to complete the request (500) */
162
+ INTERNAL_SERVER_ERROR: number;
163
+ /** The request method is not supported by the server and cannot be handled (501) */
164
+ NOT_IMPLEMENTED: number;
165
+ /** The server, while acting as a gateway or proxy, received an invalid response from the upstream server (502) */
166
+ BAD_GATEWAY: number;
167
+ /** The server is not ready to handle the request, typically due to temporary overload or maintenance (503) */
168
+ SERVICE_UNAVAILABLE: number;
169
+ /** The server, while acting as a gateway or proxy, did not get a response in time from the upstream server (504) */
170
+ GATEWAY_TIMEOUT: number;
171
+ };
172
+ /**
173
+ * Returns the reason phrase corresponding to the given HTTP status code.
174
+ * This is useful for converting status codes into human-readable messages.
175
+ *
176
+ * @param statusCode - The HTTP status code for which to get the reason phrase.
177
+ * @returns The reason phrase associated with the given status code, or "Unknown Status Code" if the status code is not recognized.
178
+ */
179
+ export declare const getHttpStatusCodeReasonPhrase: (statusCode: number) => string;