@keq-request/exception 5.0.0-alpha.24 → 5.0.0-alpha.26

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.0.0-alpha.26
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [22ce01a]
8
+ - Updated dependencies [63161c4]
9
+ - keq@5.0.0-alpha.26
10
+
11
+ ## 5.0.0-alpha.25
12
+
13
+ ### Major Changes
14
+
15
+ - 214ae66: **BREAKING CHANGE:** RequestException third parameter changed from retry: boolean to options: { fatal: boolean, response: Response }
16
+
17
+ ```javascript
18
+ // Before
19
+ new RequestException(400, "Error message", true);
20
+
21
+ // After
22
+ new RequestException(400, "Error message", {
23
+ fatal: false,
24
+ response: someResponseObject,
25
+ });
26
+ ```
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies [214ae66]
31
+ - Updated dependencies [9290139]
32
+ - keq@5.0.0-alpha.25
33
+
3
34
  ## 5.0.0-alpha.24
4
35
 
5
36
  ### Patch Changes
package/dist/index.js CHANGED
@@ -58,53 +58,53 @@ function validateStatusCode() {
58
58
  if (status >= 400 && status < 500) {
59
59
  switch (status) {
60
60
  case 400:
61
- throw new import_keq.BadRequestException(statusText);
61
+ throw new import_keq.BadRequestException(statusText, { response });
62
62
  case 401:
63
- throw new import_keq.UnauthorizedException(statusText);
63
+ throw new import_keq.UnauthorizedException(statusText, { response });
64
64
  case 403:
65
- throw new import_keq.ForbiddenException(statusText);
65
+ throw new import_keq.ForbiddenException(statusText, { response });
66
66
  case 404:
67
- throw new import_keq.NotFoundedException(statusText);
67
+ throw new import_keq.NotFoundedException(statusText, { response });
68
68
  case 405:
69
- throw new import_keq.MethodNotAllowedException(statusText);
69
+ throw new import_keq.MethodNotAllowedException(statusText, { response });
70
70
  case 406:
71
- throw new import_keq.NotAcceptableException(statusText);
71
+ throw new import_keq.NotAcceptableException(statusText, { response });
72
72
  case 407:
73
- throw new import_keq.ProxyAuthenticationRequiredException(statusText);
73
+ throw new import_keq.ProxyAuthenticationRequiredException(statusText, { response });
74
74
  case 408:
75
- throw new import_keq.RequestTimeoutException(statusText);
75
+ throw new import_keq.RequestTimeoutException(statusText, { response });
76
76
  case 409:
77
- throw new import_keq.ConflictException(statusText);
77
+ throw new import_keq.ConflictException(statusText, { response });
78
78
  case 412:
79
- throw new import_keq.PreconditionFailedException(statusText);
79
+ throw new import_keq.PreconditionFailedException(statusText, { response });
80
80
  case 413:
81
- throw new import_keq.ContentTooLargeException(statusText);
81
+ throw new import_keq.ContentTooLargeException(statusText, { response });
82
82
  case 414:
83
- throw new import_keq.UriTooLongException(statusText);
83
+ throw new import_keq.UriTooLongException(statusText, { response });
84
84
  case 415:
85
- throw new import_keq.UnsupportedMediaTypeException(statusText);
85
+ throw new import_keq.UnsupportedMediaTypeException(statusText, { response });
86
86
  case 418:
87
- throw new import_keq.ImATeapotException(statusText);
87
+ throw new import_keq.ImATeapotException(statusText, { response });
88
88
  case 429:
89
- throw new import_keq.TooManyRequestsException(statusText);
89
+ throw new import_keq.TooManyRequestsException(statusText, { response });
90
90
  default:
91
- throw new import_keq.RequestException(status, statusText, false);
91
+ throw new import_keq.RequestException(status, statusText, { fatal: true, response });
92
92
  }
93
93
  }
94
94
  if (status >= 500) {
95
95
  switch (status) {
96
96
  case 500:
97
- throw new import_keq.InternalServerErrorException(statusText);
97
+ throw new import_keq.InternalServerErrorException(statusText, { response });
98
98
  case 501:
99
- throw new import_keq.NotImplementedException(statusText);
99
+ throw new import_keq.NotImplementedException(statusText, { response });
100
100
  case 502:
101
- throw new import_keq.BadGatewayException(statusText);
101
+ throw new import_keq.BadGatewayException(statusText, { response });
102
102
  case 503:
103
- throw new import_keq.ServiceUnavailableException(statusText);
103
+ throw new import_keq.ServiceUnavailableException(statusText, { response });
104
104
  case 504:
105
- throw new import_keq.GatewayTimeoutException(statusText);
105
+ throw new import_keq.GatewayTimeoutException(statusText, { response });
106
106
  default:
107
- throw new import_keq.RequestException(status, statusText, true);
107
+ throw new import_keq.RequestException(status, statusText, { fatal: false, response });
108
108
  }
109
109
  }
110
110
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/throw-exception.ts","../src/catch-exception.ts","../src/validate-status-code.ts"],"sourcesContent":["export * from './throw-exception.js'\nexport * from './catch-exception.js'\nexport * from './validate-status-code.js'\n","import { KeqContext, KeqMiddleware } from 'keq'\nimport { Promisable } from 'type-fest'\n\n\nexport type Check = (ctx: KeqContext) => Promisable<void>\n\nexport function throwException(check: Check): KeqMiddleware {\n return async function throwException(ctx, next) {\n await next()\n\n await check(ctx)\n }\n}\n","import { KeqMiddleware } from 'keq'\nimport { Promisable } from 'type-fest'\n\n\nexport function catchException(handler: (e: unknown) => Promisable<void>): KeqMiddleware {\n return async function catchException(ctx, next) {\n try {\n await next()\n } catch (err) {\n await handler(err)\n }\n }\n}\n","import {\n BadGatewayException,\n BadRequestException,\n ConflictException,\n ForbiddenException,\n GatewayTimeoutException,\n InternalServerErrorException,\n KeqMiddleware,\n NotAcceptableException,\n NotFoundedException,\n PreconditionFailedException,\n RequestException,\n ServiceUnavailableException,\n UnauthorizedException,\n ImATeapotException,\n MethodNotAllowedException,\n UriTooLongException,\n ContentTooLargeException,\n ProxyAuthenticationRequiredException,\n RequestTimeoutException,\n TooManyRequestsException,\n NotImplementedException,\n UnsupportedMediaTypeException,\n} from 'keq'\n\nexport function validateStatusCode(): KeqMiddleware {\n return async function validateStatusCode(context, next) {\n await next()\n\n const response = context.response\n if (!response) return\n\n const { status, statusText } = response\n\n // 2xx success status codes - no error\n if (status >= 200 && status < 300) return\n\n // 3xx redirection status codes - no error (handled by fetch)\n if (status >= 300 && status < 400) return\n\n // 4xx client errors\n if (status >= 400 && status < 500) {\n switch (status) {\n case 400:\n throw new BadRequestException(statusText)\n case 401:\n throw new UnauthorizedException(statusText)\n case 403:\n throw new ForbiddenException(statusText)\n case 404:\n throw new NotFoundedException(statusText)\n case 405:\n throw new MethodNotAllowedException(statusText)\n case 406:\n throw new NotAcceptableException(statusText)\n case 407:\n throw new ProxyAuthenticationRequiredException(statusText)\n case 408:\n throw new RequestTimeoutException(statusText)\n case 409:\n throw new ConflictException(statusText)\n case 412:\n throw new PreconditionFailedException(statusText)\n case 413:\n throw new ContentTooLargeException(statusText)\n case 414:\n throw new UriTooLongException(statusText)\n case 415:\n throw new UnsupportedMediaTypeException(statusText)\n case 418:\n throw new ImATeapotException(statusText)\n case 429:\n throw new TooManyRequestsException(statusText)\n default:\n // Other 4xx errors, don't retry by default\n throw new RequestException(status, statusText, false)\n }\n }\n\n // 5xx server errors\n if (status >= 500) {\n switch (status) {\n case 500:\n throw new InternalServerErrorException(statusText)\n case 501:\n throw new NotImplementedException(statusText)\n case 502:\n throw new BadGatewayException(statusText)\n case 503:\n throw new ServiceUnavailableException(statusText)\n case 504:\n throw new GatewayTimeoutException(statusText)\n default:\n // Other 5xx errors, retry by default\n throw new RequestException(status, statusText, true)\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,SAAS,eAAe,OAA6B;AAC1D,SAAO,eAAeA,gBAAe,KAAK,MAAM;AAC9C,UAAM,KAAK;AAEX,UAAM,MAAM,GAAG;AAAA,EACjB;AACF;;;ACRO,SAAS,eAAe,SAA0D;AACvF,SAAO,eAAeC,gBAAe,KAAK,MAAM;AAC9C,QAAI;AACF,YAAM,KAAK;AAAA,IACb,SAAS,KAAK;AACZ,YAAM,QAAQ,GAAG;AAAA,IACnB;AAAA,EACF;AACF;;;ACZA,iBAuBO;AAEA,SAAS,qBAAoC;AAClD,SAAO,eAAeC,oBAAmB,SAAS,MAAM;AACtD,UAAM,KAAK;AAEX,UAAM,WAAW,QAAQ;AACzB,QAAI,CAAC,SAAU;AAEf,UAAM,EAAE,QAAQ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CAA4B,UAAU;AAAA,QAClD,KAAK;AACH,gBAAM,IAAI,mCAAwB,UAAU;AAAA,QAC9C;AAEE,gBAAM,IAAI,4BAAiB,QAAQ,YAAY,IAAI;AAAA,MACrD;AAAA,IACF;AAAA,EACF;AACF;","names":["throwException","catchException","validateStatusCode"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/throw-exception.ts","../src/catch-exception.ts","../src/validate-status-code.ts"],"sourcesContent":["export * from './throw-exception.js'\nexport * from './catch-exception.js'\nexport * from './validate-status-code.js'\n","import { KeqContext, KeqMiddleware } from 'keq'\nimport { Promisable } from 'type-fest'\n\n\nexport type Check = (ctx: KeqContext) => Promisable<void>\n\nexport function throwException(check: Check): KeqMiddleware {\n return async function throwException(ctx, next) {\n await next()\n\n await check(ctx)\n }\n}\n","import { KeqMiddleware } from 'keq'\nimport { Promisable } from 'type-fest'\n\n\nexport function catchException(handler: (e: unknown) => Promisable<void>): KeqMiddleware {\n return async function catchException(ctx, next) {\n try {\n await next()\n } catch (err) {\n await handler(err)\n }\n }\n}\n","import {\n BadGatewayException,\n BadRequestException,\n ConflictException,\n ForbiddenException,\n GatewayTimeoutException,\n InternalServerErrorException,\n KeqMiddleware,\n NotAcceptableException,\n NotFoundedException,\n PreconditionFailedException,\n RequestException,\n ServiceUnavailableException,\n UnauthorizedException,\n ImATeapotException,\n MethodNotAllowedException,\n UriTooLongException,\n ContentTooLargeException,\n ProxyAuthenticationRequiredException,\n RequestTimeoutException,\n TooManyRequestsException,\n NotImplementedException,\n UnsupportedMediaTypeException,\n} from 'keq'\n\nexport function validateStatusCode(): KeqMiddleware {\n return async function validateStatusCode(context, next) {\n await next()\n\n const response = context.response\n if (!response) return\n\n const { status, statusText } = response\n\n // 2xx success status codes - no error\n if (status >= 200 && status < 300) return\n\n // 3xx redirection status codes - no error (handled by fetch)\n if (status >= 300 && status < 400) return\n\n // 4xx client errors\n if (status >= 400 && status < 500) {\n switch (status) {\n case 400:\n throw new BadRequestException(statusText, { response })\n case 401:\n throw new UnauthorizedException(statusText, { response })\n case 403:\n throw new ForbiddenException(statusText, { response })\n case 404:\n throw new NotFoundedException(statusText, { response })\n case 405:\n throw new MethodNotAllowedException(statusText, { response })\n case 406:\n throw new NotAcceptableException(statusText, { response })\n case 407:\n throw new ProxyAuthenticationRequiredException(statusText, { response })\n case 408:\n throw new RequestTimeoutException(statusText, { response })\n case 409:\n throw new ConflictException(statusText, { response })\n case 412:\n throw new PreconditionFailedException(statusText, { response })\n case 413:\n throw new ContentTooLargeException(statusText, { response })\n case 414:\n throw new UriTooLongException(statusText, { response })\n case 415:\n throw new UnsupportedMediaTypeException(statusText, { response })\n case 418:\n throw new ImATeapotException(statusText, { response })\n case 429:\n throw new TooManyRequestsException(statusText, { response })\n default:\n // Other 4xx errors, don't retry by default\n throw new RequestException(status, statusText, { fatal: true, response })\n }\n }\n\n // 5xx server errors\n if (status >= 500) {\n switch (status) {\n case 500:\n throw new InternalServerErrorException(statusText, { response })\n case 501:\n throw new NotImplementedException(statusText, { response })\n case 502:\n throw new BadGatewayException(statusText, { response })\n case 503:\n throw new ServiceUnavailableException(statusText, { response })\n case 504:\n throw new GatewayTimeoutException(statusText, { response })\n default:\n // Other 5xx errors, retry by default\n throw new RequestException(status, statusText, { fatal: false, response })\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,SAAS,eAAe,OAA6B;AAC1D,SAAO,eAAeA,gBAAe,KAAK,MAAM;AAC9C,UAAM,KAAK;AAEX,UAAM,MAAM,GAAG;AAAA,EACjB;AACF;;;ACRO,SAAS,eAAe,SAA0D;AACvF,SAAO,eAAeC,gBAAe,KAAK,MAAM;AAC9C,QAAI;AACF,YAAM,KAAK;AAAA,IACb,SAAS,KAAK;AACZ,YAAM,QAAQ,GAAG;AAAA,IACnB;AAAA,EACF;AACF;;;ACZA,iBAuBO;AAEA,SAAS,qBAAoC;AAClD,SAAO,eAAeC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ACvD,KAAK;AACH,gBAAM,IAAI,oCAAyB,YAAY,EAAE,SAAS,CAAC;AAAA,QAC7D;AAEE,gBAAM,IAAI,4BAAiB,QAAQ,YAAY,EAAE,OAAO,MAAM,SAAS,CAAC;AAAA,MAC1E;AAAA,IACF;AAGA,QAAI,UAAU,KAAK;AACjB,cAAQ,QAAQ;AAAA,QAChB,KAAK;AACH,gBAAM,IAAI,wCAA6B,YAAY,EAAE,SAAS,CAAC;AAAA,QACjE,KAAK;AACH,gBAAM,IAAI,mCAAwB,YAAY,EAAE,SAAS,CAAC;AAAA,QAC5D,KAAK;AACH,gBAAM,IAAI,+BAAoB,YAAY,EAAE,SAAS,CAAC;AAAA,QACxD,KAAK;AACH,gBAAM,IAAI,uCAA4B,YAAY,EAAE,SAAS,CAAC;AAAA,QAChE,KAAK;AACH,gBAAM,IAAI,mCAAwB,YAAY,EAAE,SAAS,CAAC;AAAA,QAC5D;AAEE,gBAAM,IAAI,4BAAiB,QAAQ,YAAY,EAAE,OAAO,OAAO,SAAS,CAAC;AAAA,MAC3E;AAAA,IACF;AAAA,EACF;AACF;","names":["throwException","catchException","validateStatusCode"]}
package/dist/index.mjs CHANGED
@@ -52,53 +52,53 @@ function validateStatusCode() {
52
52
  if (status >= 400 && status < 500) {
53
53
  switch (status) {
54
54
  case 400:
55
- throw new BadRequestException(statusText);
55
+ throw new BadRequestException(statusText, { response });
56
56
  case 401:
57
- throw new UnauthorizedException(statusText);
57
+ throw new UnauthorizedException(statusText, { response });
58
58
  case 403:
59
- throw new ForbiddenException(statusText);
59
+ throw new ForbiddenException(statusText, { response });
60
60
  case 404:
61
- throw new NotFoundedException(statusText);
61
+ throw new NotFoundedException(statusText, { response });
62
62
  case 405:
63
- throw new MethodNotAllowedException(statusText);
63
+ throw new MethodNotAllowedException(statusText, { response });
64
64
  case 406:
65
- throw new NotAcceptableException(statusText);
65
+ throw new NotAcceptableException(statusText, { response });
66
66
  case 407:
67
- throw new ProxyAuthenticationRequiredException(statusText);
67
+ throw new ProxyAuthenticationRequiredException(statusText, { response });
68
68
  case 408:
69
- throw new RequestTimeoutException(statusText);
69
+ throw new RequestTimeoutException(statusText, { response });
70
70
  case 409:
71
- throw new ConflictException(statusText);
71
+ throw new ConflictException(statusText, { response });
72
72
  case 412:
73
- throw new PreconditionFailedException(statusText);
73
+ throw new PreconditionFailedException(statusText, { response });
74
74
  case 413:
75
- throw new ContentTooLargeException(statusText);
75
+ throw new ContentTooLargeException(statusText, { response });
76
76
  case 414:
77
- throw new UriTooLongException(statusText);
77
+ throw new UriTooLongException(statusText, { response });
78
78
  case 415:
79
- throw new UnsupportedMediaTypeException(statusText);
79
+ throw new UnsupportedMediaTypeException(statusText, { response });
80
80
  case 418:
81
- throw new ImATeapotException(statusText);
81
+ throw new ImATeapotException(statusText, { response });
82
82
  case 429:
83
- throw new TooManyRequestsException(statusText);
83
+ throw new TooManyRequestsException(statusText, { response });
84
84
  default:
85
- throw new RequestException(status, statusText, false);
85
+ throw new RequestException(status, statusText, { fatal: true, response });
86
86
  }
87
87
  }
88
88
  if (status >= 500) {
89
89
  switch (status) {
90
90
  case 500:
91
- throw new InternalServerErrorException(statusText);
91
+ throw new InternalServerErrorException(statusText, { response });
92
92
  case 501:
93
- throw new NotImplementedException(statusText);
93
+ throw new NotImplementedException(statusText, { response });
94
94
  case 502:
95
- throw new BadGatewayException(statusText);
95
+ throw new BadGatewayException(statusText, { response });
96
96
  case 503:
97
- throw new ServiceUnavailableException(statusText);
97
+ throw new ServiceUnavailableException(statusText, { response });
98
98
  case 504:
99
- throw new GatewayTimeoutException(statusText);
99
+ throw new GatewayTimeoutException(statusText, { response });
100
100
  default:
101
- throw new RequestException(status, statusText, true);
101
+ throw new RequestException(status, statusText, { fatal: false, response });
102
102
  }
103
103
  }
104
104
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/throw-exception.ts","../src/catch-exception.ts","../src/validate-status-code.ts"],"sourcesContent":["import { KeqContext, KeqMiddleware } from 'keq'\nimport { Promisable } from 'type-fest'\n\n\nexport type Check = (ctx: KeqContext) => Promisable<void>\n\nexport function throwException(check: Check): KeqMiddleware {\n return async function throwException(ctx, next) {\n await next()\n\n await check(ctx)\n }\n}\n","import { KeqMiddleware } from 'keq'\nimport { Promisable } from 'type-fest'\n\n\nexport function catchException(handler: (e: unknown) => Promisable<void>): KeqMiddleware {\n return async function catchException(ctx, next) {\n try {\n await next()\n } catch (err) {\n await handler(err)\n }\n }\n}\n","import {\n BadGatewayException,\n BadRequestException,\n ConflictException,\n ForbiddenException,\n GatewayTimeoutException,\n InternalServerErrorException,\n KeqMiddleware,\n NotAcceptableException,\n NotFoundedException,\n PreconditionFailedException,\n RequestException,\n ServiceUnavailableException,\n UnauthorizedException,\n ImATeapotException,\n MethodNotAllowedException,\n UriTooLongException,\n ContentTooLargeException,\n ProxyAuthenticationRequiredException,\n RequestTimeoutException,\n TooManyRequestsException,\n NotImplementedException,\n UnsupportedMediaTypeException,\n} from 'keq'\n\nexport function validateStatusCode(): KeqMiddleware {\n return async function validateStatusCode(context, next) {\n await next()\n\n const response = context.response\n if (!response) return\n\n const { status, statusText } = response\n\n // 2xx success status codes - no error\n if (status >= 200 && status < 300) return\n\n // 3xx redirection status codes - no error (handled by fetch)\n if (status >= 300 && status < 400) return\n\n // 4xx client errors\n if (status >= 400 && status < 500) {\n switch (status) {\n case 400:\n throw new BadRequestException(statusText)\n case 401:\n throw new UnauthorizedException(statusText)\n case 403:\n throw new ForbiddenException(statusText)\n case 404:\n throw new NotFoundedException(statusText)\n case 405:\n throw new MethodNotAllowedException(statusText)\n case 406:\n throw new NotAcceptableException(statusText)\n case 407:\n throw new ProxyAuthenticationRequiredException(statusText)\n case 408:\n throw new RequestTimeoutException(statusText)\n case 409:\n throw new ConflictException(statusText)\n case 412:\n throw new PreconditionFailedException(statusText)\n case 413:\n throw new ContentTooLargeException(statusText)\n case 414:\n throw new UriTooLongException(statusText)\n case 415:\n throw new UnsupportedMediaTypeException(statusText)\n case 418:\n throw new ImATeapotException(statusText)\n case 429:\n throw new TooManyRequestsException(statusText)\n default:\n // Other 4xx errors, don't retry by default\n throw new RequestException(status, statusText, false)\n }\n }\n\n // 5xx server errors\n if (status >= 500) {\n switch (status) {\n case 500:\n throw new InternalServerErrorException(statusText)\n case 501:\n throw new NotImplementedException(statusText)\n case 502:\n throw new BadGatewayException(statusText)\n case 503:\n throw new ServiceUnavailableException(statusText)\n case 504:\n throw new GatewayTimeoutException(statusText)\n default:\n // Other 5xx errors, retry by default\n throw new RequestException(status, statusText, true)\n }\n }\n }\n}\n"],"mappings":";AAMO,SAAS,eAAe,OAA6B;AAC1D,SAAO,eAAeA,gBAAe,KAAK,MAAM;AAC9C,UAAM,KAAK;AAEX,UAAM,MAAM,GAAG;AAAA,EACjB;AACF;;;ACRO,SAAS,eAAe,SAA0D;AACvF,SAAO,eAAeC,gBAAe,KAAK,MAAM;AAC9C,QAAI;AACF,YAAM,KAAK;AAAA,IACb,SAAS,KAAK;AACZ,YAAM,QAAQ,GAAG;AAAA,IACnB;AAAA,EACF;AACF;;;ACZA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,SAAS,qBAAoC;AAClD,SAAO,eAAeC,oBAAmB,SAAS,MAAM;AACtD,UAAM,KAAK;AAEX,UAAM,WAAW,QAAQ;AACzB,QAAI,CAAC,SAAU;AAEf,UAAM,EAAE,QAAQ,WAAW,IAAI;AAG/B,QAAI,UAAU,OAAO,SAAS,IAAK;AAGnC,QAAI,UAAU,OAAO,SAAS,IAAK;AAGnC,QAAI,UAAU,OAAO,SAAS,KAAK;AACjC,cAAQ,QAAQ;AAAA,QAChB,KAAK;AACH,gBAAM,IAA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StatusCode"]}
1
+ {"version":3,"sources":["../src/throw-exception.ts","../src/catch-exception.ts","../src/validate-status-code.ts"],"sourcesContent":["import { KeqContext, KeqMiddleware } from 'keq'\nimport { Promisable } from 'type-fest'\n\n\nexport type Check = (ctx: KeqContext) => Promisable<void>\n\nexport function throwException(check: Check): KeqMiddleware {\n return async function throwException(ctx, next) {\n await next()\n\n await check(ctx)\n }\n}\n","import { KeqMiddleware } from 'keq'\nimport { Promisable } from 'type-fest'\n\n\nexport function catchException(handler: (e: unknown) => Promisable<void>): KeqMiddleware {\n return async function catchException(ctx, next) {\n try {\n await next()\n } catch (err) {\n await handler(err)\n }\n }\n}\n","import {\n BadGatewayException,\n BadRequestException,\n ConflictException,\n ForbiddenException,\n GatewayTimeoutException,\n InternalServerErrorException,\n KeqMiddleware,\n NotAcceptableException,\n NotFoundedException,\n PreconditionFailedException,\n RequestException,\n ServiceUnavailableException,\n UnauthorizedException,\n ImATeapotException,\n MethodNotAllowedException,\n UriTooLongException,\n ContentTooLargeException,\n ProxyAuthenticationRequiredException,\n RequestTimeoutException,\n TooManyRequestsException,\n NotImplementedException,\n UnsupportedMediaTypeException,\n} from 'keq'\n\nexport function validateStatusCode(): KeqMiddleware {\n return async function validateStatusCode(context, next) {\n await next()\n\n const response = context.response\n if (!response) return\n\n const { status, statusText } = response\n\n // 2xx success status codes - no error\n if (status >= 200 && status < 300) return\n\n // 3xx redirection status codes - no error (handled by fetch)\n if (status >= 300 && status < 400) return\n\n // 4xx client errors\n if (status >= 400 && status < 500) {\n switch (status) {\n case 400:\n throw new BadRequestException(statusText, { response })\n case 401:\n throw new UnauthorizedException(statusText, { response })\n case 403:\n throw new ForbiddenException(statusText, { response })\n case 404:\n throw new NotFoundedException(statusText, { response })\n case 405:\n throw new MethodNotAllowedException(statusText, { response })\n case 406:\n throw new NotAcceptableException(statusText, { response })\n case 407:\n throw new ProxyAuthenticationRequiredException(statusText, { response })\n case 408:\n throw new RequestTimeoutException(statusText, { response })\n case 409:\n throw new ConflictException(statusText, { response })\n case 412:\n throw new PreconditionFailedException(statusText, { response })\n case 413:\n throw new ContentTooLargeException(statusText, { response })\n case 414:\n throw new UriTooLongException(statusText, { response })\n case 415:\n throw new UnsupportedMediaTypeException(statusText, { response })\n case 418:\n throw new ImATeapotException(statusText, { response })\n case 429:\n throw new TooManyRequestsException(statusText, { response })\n default:\n // Other 4xx errors, don't retry by default\n throw new RequestException(status, statusText, { fatal: true, response })\n }\n }\n\n // 5xx server errors\n if (status >= 500) {\n switch (status) {\n case 500:\n throw new InternalServerErrorException(statusText, { response })\n case 501:\n throw new NotImplementedException(statusText, { response })\n case 502:\n throw new BadGatewayException(statusText, { response })\n case 503:\n throw new ServiceUnavailableException(statusText, { response })\n case 504:\n throw new GatewayTimeoutException(statusText, { response })\n default:\n // Other 5xx errors, retry by default\n throw new RequestException(status, statusText, { fatal: false, response })\n }\n }\n }\n}\n"],"mappings":";AAMO,SAAS,eAAe,OAA6B;AAC1D,SAAO,eAAeA,gBAAe,KAAK,MAAM;AAC9C,UAAM,KAAK;AAEX,UAAM,MAAM,GAAG;AAAA,EACjB;AACF;;;ACRO,SAAS,eAAe,SAA0D;AACvF,SAAO,eAAeC,gBAAe,KAAK,MAAM;AAC9C,QAAI;AACF,YAAM,KAAK;AAAA,IACb,SAAS,KAAK;AACZ,YAAM,QAAQ,GAAG;AAAA,IACnB;AAAA,EACF;AACF;;;ACZA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,SAAS,qBAAoC;AAClD,SAAO,eAAeC,oBAAmB,SAAS,MAAM;AACtD,UAAM,KAAK;AAEX,UAAM,WAAW,QAAQ;AACzB,QAAI,CAA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gBAAM,IAAI,iBAAiB,QAAQ,YAAY,EAAE,OAAO,MAAM,SAAS,CAAC;AAAA,MAC1E;AAAA,IACF;AAGA,QAAI,UAAU,KAAK;AACjB,cAAQ,QAAQ;AAAA,QAChB,KAAK;AACH,gBAAM,IAAI,6BAA6B,YAAY,EAAE,SAAS,CAAC;AAAA,QACjE,KAAK;AACH,gBAAM,IAAI,wBAAwB,YAAY,EAAE,SAAS,CAAC;AAAA,QAC5D,KAAK;AACH,gBAAM,IAAI,oBAAoB,YAAY,EAAE,SAAS,CAAC;AAAA,QACxD,KAAK;AACH,gBAAM,IAAI,4BAA4B,YAAY,EAAE,SAAS,CAAC;AAAA,QAChE,KAAK;AACH,gBAAM,IAAI,wBAAwB,YAAY,EAAE,SAAS,CAAC;AAAA,QAC5D;AAEE,gBAAM,IAAI,iBAAiB,QAAQ,YAAY,EAAE,OAAO,OAAO,SAAS,CAAC;AAAA,MAC3E;AAAA,IACF;AAAA,EACF;AACF;","names":["throwException","catchException","validateStatusCode"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keq-request/exception",
3
- "version": "5.0.0-alpha.24",
3
+ "version": "5.0.0-alpha.26",
4
4
  "description": "Request exception for keq",
5
5
  "keywords": [
6
6
  "keq",
@@ -39,14 +39,14 @@
39
39
  "devDependencies": {
40
40
  "@scalar/openapi-types": "^0.5.2",
41
41
  "@types/node": "^20.19.25",
42
- "@keq-request/cli": "5.0.0-alpha.24",
43
- "keq": "5.0.0-alpha.24"
42
+ "@keq-request/cli": "5.0.0-alpha.26",
43
+ "keq": "5.0.0-alpha.26"
44
44
  },
45
45
  "peerDependencies": {
46
- "keq": "^5.0.0-alpha.24"
46
+ "keq": "^5.0.0-alpha.26"
47
47
  },
48
48
  "optionalDependencies": {
49
- "@keq-request/cli": "5.0.0-alpha.24"
49
+ "@keq-request/cli": "5.0.0-alpha.26"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "tsup",