@yildizpay/http-adapter 3.0.0 → 3.1.0

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.
Files changed (51) hide show
  1. package/README.md +186 -9
  2. package/README.tr.md +221 -44
  3. package/dist/contracts/http-client.contract.d.ts +0 -9
  4. package/dist/contracts/http-client.contract.js +0 -17
  5. package/dist/contracts/http-client.contract.js.map +1 -1
  6. package/dist/contracts/http-interceptor.contract.d.ts +2 -1
  7. package/dist/core/default-http-client.js +7 -6
  8. package/dist/core/default-http-client.js.map +1 -1
  9. package/dist/core/error.converter.d.ts +5 -0
  10. package/dist/core/error.converter.js +31 -0
  11. package/dist/core/error.converter.js.map +1 -0
  12. package/dist/core/http.adapter.js +11 -4
  13. package/dist/core/http.adapter.js.map +1 -1
  14. package/dist/exceptions/base-adapter.exception.d.ts +7 -0
  15. package/dist/exceptions/base-adapter.exception.js +34 -0
  16. package/dist/exceptions/base-adapter.exception.js.map +1 -0
  17. package/dist/exceptions/circuit-breaker-open.exception.d.ts +2 -2
  18. package/dist/exceptions/circuit-breaker-open.exception.js +3 -3
  19. package/dist/exceptions/circuit-breaker-open.exception.js.map +1 -1
  20. package/dist/exceptions/exception.guards.d.ts +15 -0
  21. package/dist/exceptions/exception.guards.js +48 -0
  22. package/dist/exceptions/exception.guards.js.map +1 -0
  23. package/dist/exceptions/http-exception.factory.d.ts +5 -0
  24. package/dist/exceptions/http-exception.factory.js +59 -0
  25. package/dist/exceptions/http-exception.factory.js.map +1 -0
  26. package/dist/exceptions/http-status.exceptions.d.ts +134 -0
  27. package/dist/exceptions/http-status.exceptions.js +382 -0
  28. package/dist/exceptions/http-status.exceptions.js.map +1 -0
  29. package/dist/exceptions/network-exception.factory.d.ts +6 -0
  30. package/dist/exceptions/network-exception.factory.js +35 -0
  31. package/dist/exceptions/network-exception.factory.js.map +1 -0
  32. package/dist/exceptions/network.exceptions.d.ts +25 -0
  33. package/dist/exceptions/network.exceptions.js +69 -0
  34. package/dist/exceptions/network.exceptions.js.map +1 -0
  35. package/dist/exceptions/unknown.exception.d.ts +7 -0
  36. package/dist/exceptions/unknown.exception.js +20 -0
  37. package/dist/exceptions/unknown.exception.js.map +1 -0
  38. package/dist/index.d.ts +9 -1
  39. package/dist/index.js +9 -1
  40. package/dist/index.js.map +1 -1
  41. package/dist/models/request-context.d.ts +5 -0
  42. package/dist/models/request-context.js +3 -0
  43. package/dist/models/request-context.js.map +1 -0
  44. package/dist/models/response.d.ts +8 -5
  45. package/dist/models/response.js +9 -5
  46. package/dist/models/response.js.map +1 -1
  47. package/dist/tsconfig.tsbuildinfo +1 -1
  48. package/package.json +1 -1
  49. package/dist/exceptions/http.exception.d.ts +0 -5
  50. package/dist/exceptions/http.exception.js +0 -12
  51. package/dist/exceptions/http.exception.js.map +0 -1
@@ -1,3 +1,4 @@
1
+ import { BaseAdapterException } from '../exceptions/base-adapter.exception';
1
2
  import { Request } from '../models/request';
2
3
  import { Response } from '../models/response';
3
4
  export interface HttpRequestInterceptor {
@@ -7,6 +8,6 @@ export interface HttpResponseInterceptor {
7
8
  onResponse(response: Response): Promise<Response>;
8
9
  }
9
10
  export interface HttpErrorInterceptor {
10
- onError(error: unknown, request: Request): Promise<unknown>;
11
+ onError(error: BaseAdapterException, request: Request): Promise<BaseAdapterException>;
11
12
  }
12
13
  export type HttpInterceptor = Partial<HttpRequestInterceptor> & Partial<HttpResponseInterceptor> & Partial<HttpErrorInterceptor>;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultHttpClient = exports.FetchHttpClient = void 0;
4
- const http_client_contract_1 = require("../contracts/http-client.contract");
4
+ const network_exception_factory_1 = require("../exceptions/network-exception.factory");
5
+ const http_exception_factory_1 = require("../exceptions/http-exception.factory");
6
+ const base_adapter_exception_1 = require("../exceptions/base-adapter.exception");
5
7
  class FetchHttpClient {
6
8
  async request(config) {
7
9
  const controller = new AbortController();
@@ -32,7 +34,7 @@ class FetchHttpClient {
32
34
  responseHeaders[key] = value;
33
35
  });
34
36
  if (!response.ok) {
35
- throw new http_client_contract_1.HttpClientException(`Request failed with status ${response.status}`, response.status, responseData, responseHeaders);
37
+ throw http_exception_factory_1.HttpExceptionFactory.createFromResponse(response.status, responseData, responseHeaders, `Request failed with status ${response.status}`);
36
38
  }
37
39
  return {
38
40
  data: responseData,
@@ -41,10 +43,9 @@ class FetchHttpClient {
41
43
  };
42
44
  }
43
45
  catch (error) {
44
- if (error instanceof Error && error.name === 'AbortError') {
45
- throw new http_client_contract_1.HttpClientException('Request Timeout', undefined, undefined, undefined, 'ECONNABORTED');
46
- }
47
- throw error;
46
+ if (error instanceof base_adapter_exception_1.BaseAdapterException)
47
+ throw error;
48
+ throw network_exception_factory_1.NetworkExceptionFactory.createFromNativeError(error);
48
49
  }
49
50
  finally {
50
51
  if (timeoutId) {
@@ -1 +1 @@
1
- {"version":3,"file":"default-http-client.js","sourceRoot":"","sources":["../../src/core/default-http-client.ts"],"names":[],"mappings":";;;AAAA,4EAK2C;AAQ3C,MAAa,eAAe;IACnB,KAAK,CAAC,OAAO,CAClB,MAA+B;QAE/B,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,IAAI,SAAqC,CAAC;QAE1C,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;YACzC,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QACnE,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE;gBACvC,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;oBAClC,GAAG,MAAM,CAAC,OAAO;iBAClB;gBACD,IAAI,EAAE,MAAM,CAAC,IAA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AiB,EACjB,SAAS,EACT,SAAS,EACT,SAAS,EACT,cAAc,CACf,CAAC;YACJ,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,IAAI,SAAS,EAAE,CAAC;gBACd,YAAY,CAAC,SAAS,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAnED,0CAmEC;AAEY,QAAA,iBAAiB,GAAG,IAAI,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"default-http-client.js","sourceRoot":"","sources":["../../src/core/default-http-client.ts"],"names":[],"mappings":";;;AAKA,uFAAkF;AAClF,iFAA4E;AAC5E,iFAA4E;AAQ5E,MAAa,eAAe;IACnB,KAAK,CAAC,OAAO,CAClB,MAA+B;QAE/B,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,IAAI,SAAqC,CAAC;QAE1C,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;YACzC,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QACnE,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE;gBACvC,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;oBAClC,GAAG,MAAM,CAAC,OAAO;iBAClB;gBACD,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;gBAC3D,MAAM,EAAE,UAAU,CAAC,MAAM;aAC1B,CAAC,CAAC;YAEH,IAAI,YAAY,GAAY,IAAI,CAAC;YACjC,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,c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ions/base-adapter.exception';
2
+ import { RequestContext } from '../models/request-context';
3
+ export declare class ErrorConverter {
4
+ static toAdapterException(error: unknown, requestContext?: RequestContext): BaseAdapterException;
5
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorConverter = void 0;
4
+ const base_adapter_exception_1 = require("../exceptions/base-adapter.exception");
5
+ const unknown_exception_1 = require("../exceptions/unknown.exception");
6
+ const http_exception_factory_1 = require("../exceptions/http-exception.factory");
7
+ const network_exception_factory_1 = require("../exceptions/network-exception.factory");
8
+ class ErrorConverter {
9
+ static toAdapterException(error, requestContext) {
10
+ if (error instanceof base_adapter_exception_1.BaseAdapterException)
11
+ return error;
12
+ if (error && typeof error === 'object') {
13
+ const errObj = error;
14
+ const status = errObj.status ?? errObj.response?.status;
15
+ if (typeof status === 'number') {
16
+ const data = errObj.data ?? errObj.response?.data;
17
+ const headers = errObj.headers ?? errObj.response?.headers;
18
+ const message = errObj.message ?? `Request failed with status ${status}`;
19
+ return http_exception_factory_1.HttpExceptionFactory.createFromResponse(status, data, headers, message, errObj.code, error, requestContext);
20
+ }
21
+ if (errObj.code || errObj.name === 'AbortError') {
22
+ return network_exception_factory_1.NetworkExceptionFactory.createFromNativeError(error, requestContext);
23
+ }
24
+ if (error instanceof Error)
25
+ return new unknown_exception_1.UnknownException(error.message, error, requestContext);
26
+ }
27
+ return new unknown_exception_1.UnknownException(typeof error === 'string' ? error : 'Unknown Adapter Error', error, requestContext);
28
+ }
29
+ }
30
+ exports.ErrorConverter = ErrorConverter;
31
+ //# sourceMappingURL=error.converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.converter.js","sourceRoot":"","sources":["../../src/core/error.converter.ts"],"names":[],"mappings":";;;AAAA,iFAA4E;AAC5E,uEAAmE;AACnE,iFAA4E;AAC5E,uFAAkF;AAwBlF,MAAa,cAAc;IAQlB,MAAM,CAAC,kBAAkB,CAC9B,KAAc,EACd,cAA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client");
5
5
  const response_1 = require("../models/response");
6
6
  const retry_executor_1 = require("../resilience/retry-executor");
7
+ const error_converter_1 = require("./error.converter");
7
8
  class HttpAdapter {
8
9
  constructor(interceptors, httpClient, retryPolicy, circuitBreaker) {
9
10
  this.interceptors = interceptors;
@@ -34,30 +35,36 @@ class HttpAdapter {
34
35
  processedRequest = await interceptor.onRequest(processedRequest);
35
36
  }
36
37
  }
38
+ let requestContext;
37
39
  try {
38
40
  const url = new URL(processedRequest.endpoint, processedRequest.baseUrl);
39
41
  const searchParams = new URLSearchParams(processedRequest.queryParams);
40
42
  if (searchParams.toString()) {
41
43
  url.search = searchParams.toString();
42
44
  }
45
+ requestContext = {
46
+ method: processedRequest.method,
47
+ url: url.toString(),
48
+ correlationId: processedRequest.systemCorrelationId,
49
+ };
43
50
  processedRequest.setTimestamp(new Date());
44
51
  const clientResponse = await this.httpClient.request({
45
- url: url.toString(),
52
+ url: requestContext.url,
46
53
  method: processedRequest.method,
47
54
  data: processedRequest.body,
48
55
  headers: processedRequest.headers,
49
56
  timeout: processedRequest.options?.timeout,
50
57
  });
51
- let response = response_1.Response.create(clientResponse.data, clientResponse.status, clientResponse.headers ?? null, processedRequest.systemCorrelationId);
58
+ let response = response_1.Response.create(clientResponse.data, clientResponse.status, clientResponse.headers ?? null, requestContext);
52
59
  for (const interceptor of this.interceptors) {
53
60
  if (interceptor.onResponse) {
54
- response = await interceptor.onResponse(response);
61
+ response = (await interceptor.onResponse(response));
55
62
  }
56
63
  }
57
64
  return response;
58
65
  }
59
66
  catch (error) {
60
- let propagatedError = error;
67
+ let propagatedError = error_converter_1.ErrorConverter.toAdapterException(error, requestContext);
61
68
  for (const interceptor of this.interceptors) {
62
69
  if (interceptor.onError) {
63
70
  propagatedError = await interceptor.onError(propagatedError, processedRequest);
@@ -1 +1 @@
1
- {"version":3,"file":"http.adapter.js","sourceRoot":"","sources":["../../src/core/http.adapter.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;AAE1D,iDAA8C;A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AAE,OAAO;aAC3C,CAAC,CAAC;YAGH,IAAI,QAAQ,GAAG,mBAAQ,CAAC,MAAM,CAC5B,cAAc,CAAC,IAAI,EACnB,cAAc,CAAC,MAAM,EACrB,cAAc,CAAC,OAAO,IAAI,IAAI,EAC9B,cAAc,CACf,CAAC;YAGF,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;gBAC5C,IAAI,WAAW,CAAC,UAAU,EAAE,CAAC;oBAC3B,QAAQ,GAAG,CAAC,MAAM,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAgB,CAAC;gBACrE,CAAC;YACH,CAAC;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,eAAe,GAAG,gCAAc,CAAC,kBAAkB,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;YAG/E,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;gBAC5C,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;oBACxB,eAAe,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC;gBACjF,CAAC;YACH,CAAC;YAED,MAAM,eAAe,CAAC;QACxB,CAAC;IACH,CAAC;CACF;AAxID,kCAwIC"}
@@ -0,0 +1,7 @@
1
+ export declare class BaseAdapterException extends Error {
2
+ readonly code?: string;
3
+ constructor(message: string, code?: string, cause?: unknown);
4
+ isRetryable(): boolean;
5
+ toJSON(): Record<string, unknown>;
6
+ private static serializeCause;
7
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseAdapterException = void 0;
4
+ class BaseAdapterException extends Error {
5
+ constructor(message, code, cause) {
6
+ super(message, { cause });
7
+ this.name = 'BaseAdapterException';
8
+ this.code = code;
9
+ Object.setPrototypeOf(this, BaseAdapterException.prototype);
10
+ }
11
+ isRetryable() {
12
+ return false;
13
+ }
14
+ toJSON() {
15
+ return {
16
+ name: this.name,
17
+ message: this.message,
18
+ ...(this.code !== undefined && { code: this.code }),
19
+ ...(this.cause !== undefined && { cause: BaseAdapterException.serializeCause(this.cause) }),
20
+ stack: this.stack,
21
+ };
22
+ }
23
+ static serializeCause(cause) {
24
+ if (cause instanceof BaseAdapterException) {
25
+ return cause.toJSON();
26
+ }
27
+ if (cause instanceof Error) {
28
+ return { name: cause.name, message: cause.message, stack: cause.stack };
29
+ }
30
+ return cause;
31
+ }
32
+ }
33
+ exports.BaseAdapterException = BaseAdapterException;
34
+ //# sourceMappingURL=base-adapter.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-adapter.exception.js","sourceRoot":"","sources":["../../src/exceptions/base-adapter.exception.ts"],"names":[],"mappings":";;;AAAA,MAAa,oBAAqB,SAAQ,KAAK;IAG7C,YAAY,OAAe,EAAE,IAAa,EAAE,KAAe;QACzD,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAC9D,CAAC;IAMM,WAAW;QAChB,OAAO,KAAK,CAAC;IACf,CAAC;IASM,MAAM;QACX,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;YACnD,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,oBAAoB,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3F,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,cAAc,CAAC,KAAc;QAC1C,IAAI,KAAK,YAAY,oBAAoB,EAAE,CAAC;YAC1C,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;QACxB,CAAC;QAED,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;QAC1E,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA9CD,oDA8CC"}
@@ -1,4 +1,4 @@
1
- import { HttpException } from './http.exception';
2
- export declare class CircuitBreakerOpenException extends HttpException {
1
+ import { BaseAdapterException } from './base-adapter.exception';
2
+ export declare class CircuitBreakerOpenException extends BaseAdapterException {
3
3
  constructor(message?: string);
4
4
  }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CircuitBreakerOpenException = void 0;
4
- const http_exception_1 = require("./http.exception");
5
- class CircuitBreakerOpenException extends http_exception_1.HttpException {
4
+ const base_adapter_exception_1 = require("./base-adapter.exception");
5
+ class CircuitBreakerOpenException extends base_adapter_exception_1.BaseAdapterException {
6
6
  constructor(message = 'Circuit Breaker is OPEN. Execution denied.') {
7
- super(message, null);
7
+ super(message);
8
8
  this.name = 'CircuitBreakerOpenException';
9
9
  Object.setPrototypeOf(this, CircuitBreakerOpenException.prototype);
10
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"circuit-breaker-open.exception.js","sourceRoot":"","sources":["../../src/exceptions/circuit-breaker-open.exception.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAKjD,MAAa,2BAA4B,SAAQ,8BAAa;IAC5D,YAAY,UAAkB,4CAA4C;QACxE,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,2BAA2B,CAAC,SAAS,CAAC,CAAC;IACrE,CAAC;CACF;AAND,kEAMC"}
1
+ {"version":3,"file":"circuit-breaker-open.exception.js","sourceRoot":"","sources":["../../src/exceptions/circuit-breaker-open.exception.ts"],"names":[],"mappings":";;;AAAA,qEAAgE;AAKhE,MAAa,2BAA4B,SAAQ,6CAAoB;IACnE,YAAY,UAAkB,4CAA4C;QACxE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,2BAA2B,CAAC,SAAS,CAAC,CAAC;IACrE,CAAC;CACF;AAND,kEAMC"}
@@ -0,0 +1,15 @@
1
+ import { BaseAdapterException } from './base-adapter.exception';
2
+ import { CircuitBreakerOpenException } from './circuit-breaker-open.exception';
3
+ import { HttpException } from './http-status.exceptions';
4
+ import { NetworkException, TimeoutException, ConnectionRefusedException, DnsResolutionException, SocketResetException, HostUnreachableException } from './network.exceptions';
5
+ import { UnknownException } from './unknown.exception';
6
+ export declare function isBaseAdapterException(error: unknown): error is BaseAdapterException;
7
+ export declare function isHttpException(error: unknown): error is HttpException;
8
+ export declare function isNetworkException(error: unknown): error is NetworkException;
9
+ export declare function isTimeoutException(error: unknown): error is TimeoutException;
10
+ export declare function isConnectionRefusedException(error: unknown): error is ConnectionRefusedException;
11
+ export declare function isDnsResolutionException(error: unknown): error is DnsResolutionException;
12
+ export declare function isSocketResetException(error: unknown): error is SocketResetException;
13
+ export declare function isHostUnreachableException(error: unknown): error is HostUnreachableException;
14
+ export declare function isUnknownException(error: unknown): error is UnknownException;
15
+ export declare function isCircuitBreakerOpenException(error: unknown): error is CircuitBreakerOpenException;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isBaseAdapterException = isBaseAdapterException;
4
+ exports.isHttpException = isHttpException;
5
+ exports.isNetworkException = isNetworkException;
6
+ exports.isTimeoutException = isTimeoutException;
7
+ exports.isConnectionRefusedException = isConnectionRefusedException;
8
+ exports.isDnsResolutionException = isDnsResolutionException;
9
+ exports.isSocketResetException = isSocketResetException;
10
+ exports.isHostUnreachableException = isHostUnreachableException;
11
+ exports.isUnknownException = isUnknownException;
12
+ exports.isCircuitBreakerOpenException = isCircuitBreakerOpenException;
13
+ const base_adapter_exception_1 = require("./base-adapter.exception");
14
+ const circuit_breaker_open_exception_1 = require("./circuit-breaker-open.exception");
15
+ const http_status_exceptions_1 = require("./http-status.exceptions");
16
+ const network_exceptions_1 = require("./network.exceptions");
17
+ const unknown_exception_1 = require("./unknown.exception");
18
+ function isBaseAdapterException(error) {
19
+ return error instanceof base_adapter_exception_1.BaseAdapterException;
20
+ }
21
+ function isHttpException(error) {
22
+ return error instanceof http_status_exceptions_1.HttpException;
23
+ }
24
+ function isNetworkException(error) {
25
+ return error instanceof network_exceptions_1.NetworkException;
26
+ }
27
+ function isTimeoutException(error) {
28
+ return error instanceof network_exceptions_1.TimeoutException;
29
+ }
30
+ function isConnectionRefusedException(error) {
31
+ return error instanceof network_exceptions_1.ConnectionRefusedException;
32
+ }
33
+ function isDnsResolutionException(error) {
34
+ return error instanceof network_exceptions_1.DnsResolutionException;
35
+ }
36
+ function isSocketResetException(error) {
37
+ return error instanceof network_exceptions_1.SocketResetException;
38
+ }
39
+ function isHostUnreachableException(error) {
40
+ return error instanceof network_exceptions_1.HostUnreachableException;
41
+ }
42
+ function isUnknownException(error) {
43
+ return error instanceof unknown_exception_1.UnknownException;
44
+ }
45
+ function isCircuitBreakerOpenException(error) {
46
+ return error instanceof circuit_breaker_open_exception_1.CircuitBreakerOpenException;
47
+ }
48
+ //# sourceMappingURL=exception.guards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exception.guards.js","sourceRoot":"","sources":["../../src/exceptions/exception.guards.ts"],"names":[],"mappings":";;AAaA,wDAEC;AAED,0CAEC;AAED,gDAEC;AAED,gDAEC;AAED,oEAEC;AAED,4DAEC;AAED,wDAEC;AAED,gEAEC;AAED,gDAEC;AAED,sEAIC;AArDD,qEAAgE;AAChE,qFAA+E;AAC/E,qEAAyD;AACzD,6DAO8B;AAC9B,2DAAuD;AAEvD,SAAgB,sBAAsB,CAAC,KAAc;IACnD,OAAO,KAAK,YAAY,6CAAoB,CAAC;AAC/C,CAAC;AAED,SAAgB,eAAe,CAAC,KAAc;IAC5C,OAAO,KAAK,YAAY,sCAAa,CAAC;AACxC,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,OAAO,KAAK,YAAY,qCAAgB,CAAC;AAC3C,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,OAAO,KAAK,YAAY,qCAAgB,CAAC;AAC3C,CAAC;AAED,SAAgB,4BAA4B,CAAC,KAAc;IACzD,OAAO,KAAK,YAAY,+CAA0B,CAAC;AACrD,CAAC;AAED,SAAgB,wBAAwB,CAAC,KAAc;IACrD,OAAO,KAAK,YAAY,2CAAsB,CAAC;AACjD,CAAC;AAED,SAAgB,sBAAsB,CAAC,KAAc;IACnD,OAAO,KAAK,YAAY,yCAAoB,CAAC;AAC/C,CAAC;AAED,SAAgB,0BAA0B,CAAC,KAAc;IACvD,OAAO,KAAK,YAAY,6CAAwB,CAAC;AACnD,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,OAAO,KAAK,YAAY,oCAAgB,CAAC;AAC3C,CAAC;AAED,SAAgB,6BAA6B,CAC3C,KAAc;IAEd,OAAO,KAAK,YAAY,4DAA2B,CAAC;AACtD,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { RequestContext } from '../models/request-context';
2
+ import { HttpException } from './http-status.exceptions';
3
+ export declare class HttpExceptionFactory {
4
+ static createFromResponse<T = unknown>(status: number, data?: T, headers?: Record<string, string>, message?: string, code?: string, cause?: unknown, requestContext?: RequestContext): HttpException<T>;
5
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpExceptionFactory = void 0;
4
+ const response_1 = require("../models/response");
5
+ const http_status_exceptions_1 = require("./http-status.exceptions");
6
+ const HttpStatusExceptionMap = {
7
+ 400: http_status_exceptions_1.BadRequestException,
8
+ 401: http_status_exceptions_1.UnauthorizedException,
9
+ 402: http_status_exceptions_1.PaymentRequiredException,
10
+ 403: http_status_exceptions_1.ForbiddenException,
11
+ 404: http_status_exceptions_1.NotFoundException,
12
+ 405: http_status_exceptions_1.MethodNotAllowedException,
13
+ 406: http_status_exceptions_1.NotAcceptableException,
14
+ 407: http_status_exceptions_1.ProxyAuthenticationRequiredException,
15
+ 408: http_status_exceptions_1.RequestTimeoutException,
16
+ 409: http_status_exceptions_1.ConflictException,
17
+ 410: http_status_exceptions_1.GoneException,
18
+ 411: http_status_exceptions_1.LengthRequiredException,
19
+ 412: http_status_exceptions_1.PreconditionFailedException,
20
+ 413: http_status_exceptions_1.PayloadTooLargeException,
21
+ 414: http_status_exceptions_1.URITooLongException,
22
+ 415: http_status_exceptions_1.UnsupportedMediaTypeException,
23
+ 416: http_status_exceptions_1.RangeNotSatisfiableException,
24
+ 417: http_status_exceptions_1.ExpectationFailedException,
25
+ 418: http_status_exceptions_1.ImATeapotException,
26
+ 421: http_status_exceptions_1.MisdirectedRequestException,
27
+ 422: http_status_exceptions_1.UnprocessableEntityException,
28
+ 423: http_status_exceptions_1.LockedException,
29
+ 424: http_status_exceptions_1.FailedDependencyException,
30
+ 425: http_status_exceptions_1.TooEarlyException,
31
+ 426: http_status_exceptions_1.UpgradeRequiredException,
32
+ 428: http_status_exceptions_1.PreconditionRequiredException,
33
+ 429: http_status_exceptions_1.TooManyRequestsException,
34
+ 431: http_status_exceptions_1.RequestHeaderFieldsTooLargeException,
35
+ 451: http_status_exceptions_1.UnavailableForLegalReasonsException,
36
+ 500: http_status_exceptions_1.InternalServerErrorException,
37
+ 501: http_status_exceptions_1.NotImplementedException,
38
+ 502: http_status_exceptions_1.BadGatewayException,
39
+ 503: http_status_exceptions_1.ServiceUnavailableException,
40
+ 504: http_status_exceptions_1.GatewayTimeoutException,
41
+ 505: http_status_exceptions_1.HTTPVersionNotSupportedException,
42
+ 506: http_status_exceptions_1.VariantAlsoNegotiatesException,
43
+ 507: http_status_exceptions_1.InsufficientStorageException,
44
+ 508: http_status_exceptions_1.LoopDetectedException,
45
+ 510: http_status_exceptions_1.NotExtendedException,
46
+ 511: http_status_exceptions_1.NetworkAuthenticationRequiredException,
47
+ };
48
+ class HttpExceptionFactory {
49
+ static createFromResponse(status, data, headers, message, code, cause, requestContext) {
50
+ const response = response_1.Response.create(data, status, headers ?? null, requestContext);
51
+ const ExceptionClass = HttpStatusExceptionMap[status];
52
+ if (ExceptionClass) {
53
+ return new ExceptionClass(response, message, code, cause);
54
+ }
55
+ return new http_status_exceptions_1.HttpException(response, message ?? `Request failed with status ${status}`, code, cause);
56
+ }
57
+ }
58
+ exports.HttpExceptionFactory = HttpExceptionFactory;
59
+ //# sourceMappingURL=http-exception.factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-exception.factory.js","sourceRoot":"","sources":["../../src/exceptions/http-exception.factory.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAE9C,qEA0CkC;AAqBlC,MAAM,sBAAsB,GAAkD;IAC5E,GAAG,EAAE,4CAAmB;IACxB,GAAG,EAAE,8CAAqB;IAC1B,GAAG,EAAE,iDAAwB;IAC7B,GAAG,EAAE,2CAAkB;IACvB,GAAG,EAAE,0CAAiB;IACtB,GAAG,EAAE,kDAAyB;IAC9B,GAAG,EAAE,+CAAsB;IAC3B,GAAG,EAAE,6DAAoC;IACzC,GAAG,EAAE,gDAAuB;IAC5B,GAAG,EAAE,0CAAiB;IACtB,GAAG,EAAE,sCAAa;IAClB,GAAG,EAAE,gDAAuB;IAC5B,GAAG,EAAE,oDAA2B;IAChC,GAAG,EAAE,iDAAwB;I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AAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;CACF;AAxCD,oDAwCC"}
@@ -0,0 +1,134 @@
1
+ import { Response } from '../models/response';
2
+ import { BaseAdapterException } from './base-adapter.exception';
3
+ export declare class HttpException<T = unknown> extends BaseAdapterException {
4
+ readonly response: Response<T>;
5
+ constructor(response: Response<T>, message: string, code?: string, cause?: unknown);
6
+ toJSON(): Record<string, unknown>;
7
+ isClientError(): boolean;
8
+ isServerError(): boolean;
9
+ getRetryAfterMs(): number | undefined;
10
+ }
11
+ export declare class BadRequestException<T = unknown> extends HttpException<T> {
12
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
13
+ }
14
+ export declare class UnauthorizedException<T = unknown> extends HttpException<T> {
15
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
16
+ }
17
+ export declare class PaymentRequiredException<T = unknown> extends HttpException<T> {
18
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
19
+ }
20
+ export declare class ForbiddenException<T = unknown> extends HttpException<T> {
21
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
22
+ }
23
+ export declare class NotFoundException<T = unknown> extends HttpException<T> {
24
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
25
+ }
26
+ export declare class MethodNotAllowedException<T = unknown> extends HttpException<T> {
27
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
28
+ }
29
+ export declare class NotAcceptableException<T = unknown> extends HttpException<T> {
30
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
31
+ }
32
+ export declare class ProxyAuthenticationRequiredException<T = unknown> extends HttpException<T> {
33
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
34
+ }
35
+ export declare class RequestTimeoutException<T = unknown> extends HttpException<T> {
36
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
37
+ }
38
+ export declare class ConflictException<T = unknown> extends HttpException<T> {
39
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
40
+ }
41
+ export declare class GoneException<T = unknown> extends HttpException<T> {
42
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
43
+ }
44
+ export declare class LengthRequiredException<T = unknown> extends HttpException<T> {
45
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
46
+ }
47
+ export declare class PreconditionFailedException<T = unknown> extends HttpException<T> {
48
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
49
+ }
50
+ export declare class PayloadTooLargeException<T = unknown> extends HttpException<T> {
51
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
52
+ }
53
+ export declare class URITooLongException<T = unknown> extends HttpException<T> {
54
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
55
+ }
56
+ export declare class UnsupportedMediaTypeException<T = unknown> extends HttpException<T> {
57
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
58
+ }
59
+ export declare class RangeNotSatisfiableException<T = unknown> extends HttpException<T> {
60
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
61
+ }
62
+ export declare class ExpectationFailedException<T = unknown> extends HttpException<T> {
63
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
64
+ }
65
+ export declare class ImATeapotException<T = unknown> extends HttpException<T> {
66
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
67
+ }
68
+ export declare class MisdirectedRequestException<T = unknown> extends HttpException<T> {
69
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
70
+ }
71
+ export declare class UnprocessableEntityException<T = unknown> extends HttpException<T> {
72
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
73
+ }
74
+ export declare class LockedException<T = unknown> extends HttpException<T> {
75
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
76
+ }
77
+ export declare class FailedDependencyException<T = unknown> extends HttpException<T> {
78
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
79
+ }
80
+ export declare class TooEarlyException<T = unknown> extends HttpException<T> {
81
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
82
+ }
83
+ export declare class UpgradeRequiredException<T = unknown> extends HttpException<T> {
84
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
85
+ }
86
+ export declare class PreconditionRequiredException<T = unknown> extends HttpException<T> {
87
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
88
+ }
89
+ export declare class TooManyRequestsException<T = unknown> extends HttpException<T> {
90
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
91
+ isRetryable(): boolean;
92
+ }
93
+ export declare class RequestHeaderFieldsTooLargeException<T = unknown> extends HttpException<T> {
94
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
95
+ }
96
+ export declare class UnavailableForLegalReasonsException<T = unknown> extends HttpException<T> {
97
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
98
+ }
99
+ export declare class InternalServerErrorException<T = unknown> extends HttpException<T> {
100
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
101
+ }
102
+ export declare class NotImplementedException<T = unknown> extends HttpException<T> {
103
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
104
+ }
105
+ export declare class BadGatewayException<T = unknown> extends HttpException<T> {
106
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
107
+ isRetryable(): boolean;
108
+ }
109
+ export declare class ServiceUnavailableException<T = unknown> extends HttpException<T> {
110
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
111
+ isRetryable(): boolean;
112
+ }
113
+ export declare class GatewayTimeoutException<T = unknown> extends HttpException<T> {
114
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
115
+ isRetryable(): boolean;
116
+ }
117
+ export declare class HTTPVersionNotSupportedException<T = unknown> extends HttpException<T> {
118
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
119
+ }
120
+ export declare class VariantAlsoNegotiatesException<T = unknown> extends HttpException<T> {
121
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
122
+ }
123
+ export declare class InsufficientStorageException<T = unknown> extends HttpException<T> {
124
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
125
+ }
126
+ export declare class LoopDetectedException<T = unknown> extends HttpException<T> {
127
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
128
+ }
129
+ export declare class NotExtendedException<T = unknown> extends HttpException<T> {
130
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
131
+ }
132
+ export declare class NetworkAuthenticationRequiredException<T = unknown> extends HttpException<T> {
133
+ constructor(response: Response<T>, message?: string, code?: string, cause?: unknown);
134
+ }