@keq-request/exception 5.0.0-alpha.19 → 5.0.0-alpha.21

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,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.0.0-alpha.21
4
+
5
+ ### Patch Changes
6
+
7
+ - b36df33: ValidateStatusCode plugin generate wrong code
8
+ - Updated dependencies [90311b3]
9
+ - keq@5.0.0-alpha.21
10
+
11
+ ## 5.0.0-alpha.20
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [1f367c0]
16
+ - keq@5.0.0-alpha.20
17
+
3
18
  ## 5.0.0-alpha.19
4
19
 
5
20
  ### Patch Changes
package/dist/index.js CHANGED
@@ -65,14 +65,28 @@ function validateStatusCode() {
65
65
  throw new import_keq.ForbiddenException(statusText);
66
66
  case 404:
67
67
  throw new import_keq.NotFoundedException(statusText);
68
+ case 405:
69
+ throw new import_keq.MethodNotAllowedException(statusText);
68
70
  case 406:
69
71
  throw new import_keq.NotAcceptableException(statusText);
72
+ case 407:
73
+ throw new import_keq.ProxyAuthenticationRequiredException(statusText);
74
+ case 408:
75
+ throw new import_keq.RequestTimeoutException(statusText);
70
76
  case 409:
71
77
  throw new import_keq.ConflictException(statusText);
72
78
  case 412:
73
79
  throw new import_keq.PreconditionFailedException(statusText);
80
+ case 413:
81
+ throw new import_keq.ContentTooLargeException(statusText);
82
+ case 414:
83
+ throw new import_keq.UriTooLongException(statusText);
84
+ case 415:
85
+ throw new import_keq.UnsupportedMediaTypeException(statusText);
74
86
  case 418:
75
87
  throw new import_keq.ImATeapotException(statusText);
88
+ case 429:
89
+ throw new import_keq.TooManyRequestsException(statusText);
76
90
  default:
77
91
  throw new import_keq.RequestException(status, statusText, false);
78
92
  }
@@ -81,6 +95,8 @@ function validateStatusCode() {
81
95
  switch (status) {
82
96
  case 500:
83
97
  throw new import_keq.InternalServerErrorException(statusText);
98
+ case 501:
99
+ throw new import_keq.NotImplementedException(statusText);
84
100
  case 502:
85
101
  throw new import_keq.BadGatewayException(statusText);
86
102
  case 503:
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} from 'keq'\n\nexport function validateStatusCode(): KeqMiddleware {\n return async (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 406:\n throw new NotAcceptableException(statusText)\n case 409:\n throw new ConflictException(statusText)\n case 412:\n throw new PreconditionFailedException(statusText)\n case 418:\n throw new ImATeapotException(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 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,iBAeO;AAEA,SAAS,qBAAoC;AAClD,SAAO,OAAO,SAAS,SAAS;AAC9B,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,IAAI,+BAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,iCAAsB,UAAU;AAAA,QAC5C,KAAK;AACH,gBAAM,IAAI,8BAAmB,UAAU;AAAA,QACzC,KAAK;AACH,gBAAM,IAAI,+BAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,kCAAuB,UAAU;AAAA,QAC7C,KAAK;AACH,gBAAM,IAAI,6BAAkB,UAAU;AAAA,QACxC,KAAK;AACH,gBAAM,IAAI,uCAA4B,UAAU;AAAA,QAClD,KAAK;AACH,gBAAM,IAAI,8BAAmB,UAAU;AAAA,QACzC;AAEE,gBAAM,IAAI,4BAAiB,QAAQ,YAAY,KAAK;AAAA,MACtD;AAAA,IACF;AAGA,QAAI,UAAU,KAAK;AACjB,cAAQ,QAAQ;AAAA,QAChB,KAAK;AACH,gBAAM,IAAI,wCAA6B,UAAU;AAAA,QACnD,KAAK;AACH,gBAAM,IAAI,+BAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,uCAA4B,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"]}
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 (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,OAAO,SAAS,SAAS;AAC9B,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,IAAI,+BAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,iCAAsB,UAAU;AAAA,QAC5C,KAAK;AACH,gBAAM,IAAI,8BAAmB,UAAU;AAAA,QACzC,KAAK;AACH,gBAAM,IAAI,+BAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,qCAA0B,UAAU;AAAA,QAChD,KAAK;AACH,gBAAM,IAAI,kCAAuB,UAAU;AAAA,QAC7C,KAAK;AACH,gBAAM,IAAI,gDAAqC,UAAU;AAAA,QAC3D,KAAK;AACH,gBAAM,IAAI,mCAAwB,UAAU;AAAA,QAC9C,KAAK;AACH,gBAAM,IAAI,6BAAkB,UAAU;AAAA,QACxC,KAAK;AACH,gBAAM,IAAI,uCAA4B,UAAU;AAAA,QAClD,KAAK;AACH,gBAAM,IAAI,oCAAyB,UAAU;AAAA,QAC/C,KAAK;AACH,gBAAM,IAAI,+BAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,yCAA8B,UAAU;AAAA,QACpD,KAAK;AACH,gBAAM,IAAI,8BAAmB,UAAU;AAAA,QACzC,KAAK;AACH,gBAAM,IAAI,oCAAyB,UAAU;AAAA,QAC/C;AAEE,gBAAM,IAAI,4BAAiB,QAAQ,YAAY,KAAK;AAAA,MACtD;AAAA,IACF;AAGA,QAAI,UAAU,KAAK;AACjB,cAAQ,QAAQ;AAAA,QAChB,KAAK;AACH,gBAAM,IAAI,wCAA6B,UAAU;AAAA,QACnD,KAAK;AACH,gBAAM,IAAI,mCAAwB,UAAU;AAAA,QAC9C,KAAK;AACH,gBAAM,IAAI,+BAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,uCAA4B,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"]}
package/dist/index.mjs CHANGED
@@ -31,7 +31,15 @@ import {
31
31
  RequestException,
32
32
  ServiceUnavailableException,
33
33
  UnauthorizedException,
34
- ImATeapotException
34
+ ImATeapotException,
35
+ MethodNotAllowedException,
36
+ UriTooLongException,
37
+ ContentTooLargeException,
38
+ ProxyAuthenticationRequiredException,
39
+ RequestTimeoutException,
40
+ TooManyRequestsException,
41
+ NotImplementedException,
42
+ UnsupportedMediaTypeException
35
43
  } from "keq";
36
44
  function validateStatusCode() {
37
45
  return async (context, next) => {
@@ -51,14 +59,28 @@ function validateStatusCode() {
51
59
  throw new ForbiddenException(statusText);
52
60
  case 404:
53
61
  throw new NotFoundedException(statusText);
62
+ case 405:
63
+ throw new MethodNotAllowedException(statusText);
54
64
  case 406:
55
65
  throw new NotAcceptableException(statusText);
66
+ case 407:
67
+ throw new ProxyAuthenticationRequiredException(statusText);
68
+ case 408:
69
+ throw new RequestTimeoutException(statusText);
56
70
  case 409:
57
71
  throw new ConflictException(statusText);
58
72
  case 412:
59
73
  throw new PreconditionFailedException(statusText);
74
+ case 413:
75
+ throw new ContentTooLargeException(statusText);
76
+ case 414:
77
+ throw new UriTooLongException(statusText);
78
+ case 415:
79
+ throw new UnsupportedMediaTypeException(statusText);
60
80
  case 418:
61
81
  throw new ImATeapotException(statusText);
82
+ case 429:
83
+ throw new TooManyRequestsException(statusText);
62
84
  default:
63
85
  throw new RequestException(status, statusText, false);
64
86
  }
@@ -67,6 +89,8 @@ function validateStatusCode() {
67
89
  switch (status) {
68
90
  case 500:
69
91
  throw new InternalServerErrorException(statusText);
92
+ case 501:
93
+ throw new NotImplementedException(statusText);
70
94
  case 502:
71
95
  throw new BadGatewayException(statusText);
72
96
  case 503:
@@ -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} from 'keq'\n\nexport function validateStatusCode(): KeqMiddleware {\n return async (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 406:\n throw new NotAcceptableException(statusText)\n case 409:\n throw new ConflictException(statusText)\n case 412:\n throw new PreconditionFailedException(statusText)\n case 418:\n throw new ImATeapotException(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 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,OACK;AAEA,SAAS,qBAAoC;AAClD,SAAO,OAAO,SAAS,SAAS;AAC9B,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,IAAI,oBAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,sBAAsB,UAAU;AAAA,QAC5C,KAAK;AACH,gBAAM,IAAI,mBAAmB,UAAU;AAAA,QACzC,KAAK;AACH,gBAAM,IAAI,oBAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,uBAAuB,UAAU;AAAA,QAC7C,KAAK;AACH,gBAAM,IAAI,kBAAkB,UAAU;AAAA,QACxC,KAAK;AACH,gBAAM,IAAI,4BAA4B,UAAU;AAAA,QAClD,KAAK;AACH,gBAAM,IAAI,mBAAmB,UAAU;AAAA,QACzC;AAEE,gBAAM,IAAI,iBAAiB,QAAQ,YAAY,KAAK;AAAA,MACtD;AAAA,IACF;AAGA,QAAI,UAAU,KAAK;AACjB,cAAQ,QAAQ;AAAA,QAChB,KAAK;AACH,gBAAM,IAAI,6BAA6B,UAAU;AAAA,QACnD,KAAK;AACH,gBAAM,IAAI,oBAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,4BAA4B,UAAU;AAAA,QAClD,KAAK;AACH,gBAAM,IAAI,wBAAwB,UAAU;AAAA,QAC9C;AAEE,gBAAM,IAAI,iBAAiB,QAAQ,YAAY,IAAI;AAAA,MACrD;AAAA,IACF;AAAA,EACF;AACF;","names":["throwException","catchException"]}
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 (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,OAAO,SAAS,SAAS;AAC9B,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,IAAI,oBAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,sBAAsB,UAAU;AAAA,QAC5C,KAAK;AACH,gBAAM,IAAI,mBAAmB,UAAU;AAAA,QACzC,KAAK;AACH,gBAAM,IAAI,oBAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,0BAA0B,UAAU;AAAA,QAChD,KAAK;AACH,gBAAM,IAAI,uBAAuB,UAAU;AAAA,QAC7C,KAAK;AACH,gBAAM,IAAI,qCAAqC,UAAU;AAAA,QAC3D,KAAK;AACH,gBAAM,IAAI,wBAAwB,UAAU;AAAA,QAC9C,KAAK;AACH,gBAAM,IAAI,kBAAkB,UAAU;AAAA,QACxC,KAAK;AACH,gBAAM,IAAI,4BAA4B,UAAU;AAAA,QAClD,KAAK;AACH,gBAAM,IAAI,yBAAyB,UAAU;AAAA,QAC/C,KAAK;AACH,gBAAM,IAAI,oBAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,8BAA8B,UAAU;AAAA,QACpD,KAAK;AACH,gBAAM,IAAI,mBAAmB,UAAU;AAAA,QACzC,KAAK;AACH,gBAAM,IAAI,yBAAyB,UAAU;AAAA,QAC/C;AAEE,gBAAM,IAAI,iBAAiB,QAAQ,YAAY,KAAK;AAAA,MACtD;AAAA,IACF;AAGA,QAAI,UAAU,KAAK;AACjB,cAAQ,QAAQ;AAAA,QAChB,KAAK;AACH,gBAAM,IAAI,6BAA6B,UAAU;AAAA,QACnD,KAAK;AACH,gBAAM,IAAI,wBAAwB,UAAU;AAAA,QAC9C,KAAK;AACH,gBAAM,IAAI,oBAAoB,UAAU;AAAA,QAC1C,KAAK;AACH,gBAAM,IAAI,4BAA4B,UAAU;AAAA,QAClD,KAAK;AACH,gBAAM,IAAI,wBAAwB,UAAU;AAAA,QAC9C;AAEE,gBAAM,IAAI,iBAAiB,QAAQ,YAAY,IAAI;AAAA,MACrD;AAAA,IACF;AAAA,EACF;AACF;","names":["throwException","catchException"]}
@@ -24,7 +24,7 @@ __export(index_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(index_exports);
26
26
 
27
- // plugins/validate-response.ts
27
+ // plugins/validate-status-code.ts
28
28
  var import_cli = require("@keq-request/cli");
29
29
  var ValidateStatusCodePlugin = class _ValidateStatusCodePlugin {
30
30
  constructor(options = {}) {
@@ -69,16 +69,16 @@ var ValidateStatusCodePlugin = class _ValidateStatusCodePlugin {
69
69
  });
70
70
  });
71
71
  compiler.hooks.afterCompileKeqRequest.tap(_ValidateStatusCodePlugin.name, (artifact) => {
72
- artifact.addDependence("@keq-request/exception", ["validateResponse"]);
72
+ artifact.addDependence("@keq-request/exception", ["validateStatusCode"]);
73
73
  if (!this.options.modules) {
74
- artifact.anchor.prepend("file:end", "request.use(validateResponse())\n");
74
+ artifact.anchor.prepend("file:end", "request.use(validateStatusCode())\n");
75
75
  } else {
76
76
  artifact.anchor.prepend(
77
77
  "file:end",
78
78
  [
79
79
  "request",
80
80
  " .useRouter()",
81
- ...this.options.modules.map((moduleName) => ` .module(${JSON.stringify(moduleName)}, validateResponse())`),
81
+ ...this.options.modules.map((moduleName) => ` .module(${JSON.stringify(moduleName)}, validateStatusCode())`),
82
82
  ""
83
83
  ].join("\n")
84
84
  );
@@ -1,4 +1,4 @@
1
- // plugins/validate-response.ts
1
+ // plugins/validate-status-code.ts
2
2
  import { ApiDocumentV3_1 } from "@keq-request/cli";
3
3
  var ValidateStatusCodePlugin = class _ValidateStatusCodePlugin {
4
4
  constructor(options = {}) {
@@ -43,16 +43,16 @@ var ValidateStatusCodePlugin = class _ValidateStatusCodePlugin {
43
43
  });
44
44
  });
45
45
  compiler.hooks.afterCompileKeqRequest.tap(_ValidateStatusCodePlugin.name, (artifact) => {
46
- artifact.addDependence("@keq-request/exception", ["validateResponse"]);
46
+ artifact.addDependence("@keq-request/exception", ["validateStatusCode"]);
47
47
  if (!this.options.modules) {
48
- artifact.anchor.prepend("file:end", "request.use(validateResponse())\n");
48
+ artifact.anchor.prepend("file:end", "request.use(validateStatusCode())\n");
49
49
  } else {
50
50
  artifact.anchor.prepend(
51
51
  "file:end",
52
52
  [
53
53
  "request",
54
54
  " .useRouter()",
55
- ...this.options.modules.map((moduleName) => ` .module(${JSON.stringify(moduleName)}, validateResponse())`),
55
+ ...this.options.modules.map((moduleName) => ` .module(${JSON.stringify(moduleName)}, validateStatusCode())`),
56
56
  ""
57
57
  ].join("\n")
58
58
  );
@@ -1 +1 @@
1
- {"version":3,"file":"validate-status-code.d.ts","sourceRoot":"","sources":["../src/validate-status-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,aAAa,EAQd,MAAM,KAAK,CAAA;AAEZ,wBAAgB,kBAAkB,IAAI,aAAa,CAyDlD"}
1
+ {"version":3,"file":"validate-status-code.d.ts","sourceRoot":"","sources":["../src/validate-status-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,aAAa,EAgBd,MAAM,KAAK,CAAA;AAEZ,wBAAgB,kBAAkB,IAAI,aAAa,CAyElD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keq-request/exception",
3
- "version": "5.0.0-alpha.19",
3
+ "version": "5.0.0-alpha.21",
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.19",
43
- "keq": "5.0.0-alpha.19"
42
+ "@keq-request/cli": "5.0.0-alpha.21",
43
+ "keq": "5.0.0-alpha.21"
44
44
  },
45
45
  "peerDependencies": {
46
- "keq": "^5.0.0-alpha.19"
46
+ "keq": "^5.0.0-alpha.21"
47
47
  },
48
48
  "optionalDependencies": {
49
- "@keq-request/cli": "5.0.0-alpha.19"
49
+ "@keq-request/cli": "5.0.0-alpha.21"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "tsup",
package/plugins/index.ts CHANGED
@@ -1 +1 @@
1
- export * from './validate-response.js'
1
+ export * from './validate-status-code.js'
@@ -63,19 +63,19 @@ export class ValidateStatusCodePlugin implements Plugin {
63
63
  })
64
64
  })
65
65
 
66
- // inject validateResponse middleware into generated code
66
+ // inject validateStatusCode middleware into generated code
67
67
  compiler.hooks.afterCompileKeqRequest.tap(ValidateStatusCodePlugin.name, (artifact: Artifact) => {
68
- artifact.addDependence('@keq-request/exception', ['validateResponse'])
68
+ artifact.addDependence('@keq-request/exception', ['validateStatusCode'])
69
69
 
70
70
  if (!this.options.modules) {
71
- artifact.anchor.prepend('file:end', 'request.use(validateResponse())\n')
71
+ artifact.anchor.prepend('file:end', 'request.use(validateStatusCode())\n')
72
72
  } else {
73
73
  artifact.anchor.prepend(
74
74
  'file:end',
75
75
  [
76
76
  'request',
77
77
  ' .useRouter()',
78
- ...this.options.modules.map((moduleName) => ` .module(${JSON.stringify(moduleName)}, validateResponse())`),
78
+ ...this.options.modules.map((moduleName) => ` .module(${JSON.stringify(moduleName)}, validateStatusCode())`),
79
79
  '',
80
80
  ].join('\n'),
81
81
  )