@rainbow-o23/n3 1.0.40 → 1.0.41

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/README.md CHANGED
@@ -602,18 +602,18 @@ CFG_ENDPOINTS_ORDER_PAYMENT_URL=https://order.com/payment
602
602
 
603
603
  #### Constructor Parameters
604
604
 
605
- | Name | Type | Default Value | Comments |
606
- |----------------------|------------------------------------------------------------|---------------|----------------------------------------------------------------------------------------------------------------------|
607
- | endpointSystemCode | string | | Endpoint system code. |
608
- | endpointName | string | | Endpoint name. |
609
- | urlGenerate | ScriptFuncOrBody\<HttpGenerateUrl> | | Endpoint url generator, `$endpointUrl`. |
610
- | method | string | | Http method, default `post`. |
611
- | timeout | number | | Endpoint timeout, in seconds. |
612
- | headersGenerate | ScriptFuncOrBody\<HttpGenerateHeaders> | | Endpoint request headers generator. |
613
- | bodyUsed | boolean | | Send request with body or not, or automatically disregards the body when sending a `get` request when not specified. |
614
- | bodyGenerate | ScriptFuncOrBody\<HttpGenerateBody> | | Endpoint request body generator. |
615
- | responseGenerate | ScriptFuncOrBody\<HttpGenerateResponse> | | Endpoint response body generator, `$response`. |
616
- | responseErrorHandles | {[key: HttpErrorCode]: ScriptFuncOrBody\<HttpHandleError>} | | Endpoint response error handlers. |
605
+ | Name | Type | Default Value | Comments |
606
+ |----------------------|--------------------------------------------------------------------------------------------------------|---------------|----------------------------------------------------------------------------------------------------------------------|
607
+ | endpointSystemCode | string | | Endpoint system code. |
608
+ | endpointName | string | | Endpoint name. |
609
+ | urlGenerate | ScriptFuncOrBody\<HttpGenerateUrl> | | Endpoint url generator, `$endpointUrl`. |
610
+ | method | string | | Http method, default `post`. |
611
+ | timeout | number | | Endpoint timeout, in seconds. |
612
+ | headersGenerate | ScriptFuncOrBody\<HttpGenerateHeaders> | | Endpoint request headers generator. |
613
+ | bodyUsed | boolean | | Send request with body or not, or automatically disregards the body when sending a `get` request when not specified. |
614
+ | bodyGenerate | ScriptFuncOrBody\<HttpGenerateBody> | | Endpoint request body generator. |
615
+ | responseGenerate | ScriptFuncOrBody\<HttpGenerateResponse> | | Endpoint response body generator, `$response`. |
616
+ | responseErrorHandles | ScriptFuncOrBody\<HttpHandleError><br>or<br>{[key: HttpErrorCode]: ScriptFuncOrBody\<HttpHandleError>} | | Endpoint response error handlers. |
617
617
 
618
618
  ## Installation
619
619
 
package/index.cjs CHANGED
@@ -1297,12 +1297,21 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1297
1297
  throw e;
1298
1298
  }
1299
1299
  });
1300
- if (options.responseErrorHandles) {
1301
- const defaultHandler = async (options, _$helpers, _$) => {
1302
- throw new n1.UncatchableError(ERR_FETCH_ERROR, `Error[${options.$errorCode}] caught when fetch data from remote[${options.$url}].`);
1303
- };
1304
- const createDefaultHandler = () => defaultHandler;
1305
- const getVariableNames = () => this.getErrorHandlerVariableName();
1300
+ const defaultHandler = async (options, _$helpers, _$) => {
1301
+ throw new n1.UncatchableError(ERR_FETCH_ERROR, `Error[${options.$errorCode}] caught when fetch data from remote[${options.$url}].`);
1302
+ };
1303
+ const createDefaultHandler = () => defaultHandler;
1304
+ const getVariableNames = () => this.getErrorHandlerVariableName();
1305
+ if (typeof options.responseErrorHandles === 'string' || typeof options.responseErrorHandles === 'function') {
1306
+ this._responseErrorHandleFunc = Utils.createAsyncFunction(options.responseErrorHandles, {
1307
+ createDefault: createDefaultHandler, getVariableNames,
1308
+ error: (e) => {
1309
+ this.getLogger().error(`Failed on create function for response error handler, snippet is [${options.responseErrorHandles}].`);
1310
+ throw e;
1311
+ }
1312
+ });
1313
+ }
1314
+ else if (options.responseErrorHandles != null) {
1306
1315
  const handlers = Object.keys(options.responseErrorHandles).reduce((handlers, status) => {
1307
1316
  handlers[status] = Utils.createAsyncFunction(options.responseErrorHandles[status], {
1308
1317
  createDefault: createDefaultHandler, getVariableNames,
package/index.js CHANGED
@@ -1295,12 +1295,21 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1295
1295
  throw e;
1296
1296
  }
1297
1297
  });
1298
- if (options.responseErrorHandles) {
1299
- const defaultHandler = async (options, _$helpers, _$) => {
1300
- throw new UncatchableError(ERR_FETCH_ERROR, `Error[${options.$errorCode}] caught when fetch data from remote[${options.$url}].`);
1301
- };
1302
- const createDefaultHandler = () => defaultHandler;
1303
- const getVariableNames = () => this.getErrorHandlerVariableName();
1298
+ const defaultHandler = async (options, _$helpers, _$) => {
1299
+ throw new UncatchableError(ERR_FETCH_ERROR, `Error[${options.$errorCode}] caught when fetch data from remote[${options.$url}].`);
1300
+ };
1301
+ const createDefaultHandler = () => defaultHandler;
1302
+ const getVariableNames = () => this.getErrorHandlerVariableName();
1303
+ if (typeof options.responseErrorHandles === 'string' || typeof options.responseErrorHandles === 'function') {
1304
+ this._responseErrorHandleFunc = Utils.createAsyncFunction(options.responseErrorHandles, {
1305
+ createDefault: createDefaultHandler, getVariableNames,
1306
+ error: (e) => {
1307
+ this.getLogger().error(`Failed on create function for response error handler, snippet is [${options.responseErrorHandles}].`);
1308
+ throw e;
1309
+ }
1310
+ });
1311
+ }
1312
+ else if (options.responseErrorHandles != null) {
1304
1313
  const handlers = Object.keys(options.responseErrorHandles).reduce((handlers, status) => {
1305
1314
  handlers[status] = Utils.createAsyncFunction(options.responseErrorHandles[status], {
1306
1315
  createDefault: createDefaultHandler, getVariableNames,
@@ -11,7 +11,7 @@ export interface FetchPipelineStepOptions<In = PipelineStepPayload, Out = Pipeli
11
11
  bodyUsed?: boolean;
12
12
  bodyGenerate?: ScriptFuncOrBody<HttpGenerateBody<In, InFragment>>;
13
13
  responseGenerate?: ScriptFuncOrBody<HttpGenerateResponse<In, InFragment>>;
14
- responseErrorHandles?: {
14
+ responseErrorHandles?: ScriptFuncOrBody<HttpHandleError<In, InFragment, OutFragment>> | {
15
15
  [key: HttpErrorCode]: ScriptFuncOrBody<HttpHandleError<In, InFragment, OutFragment>>;
16
16
  };
17
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rainbow-o23/n3",
3
- "version": "1.0.40",
3
+ "version": "1.0.41",
4
4
  "description": "o23 pipelines",
5
5
  "main": "index.cjs",
6
6
  "module": "index.js",
@@ -21,7 +21,7 @@
21
21
  "url": "https://github.com/InsureMO/rainbow-o23/issues"
22
22
  },
23
23
  "dependencies": {
24
- "@rainbow-o23/n1": "1.0.40",
24
+ "@rainbow-o23/n1": "1.0.41",
25
25
  "node-fetch": "2.6.7",
26
26
  "typeorm": "^0.3.17"
27
27
  },
@@ -26,9 +26,8 @@ export interface FetchPipelineStepOptions<In = PipelineStepPayload, Out = Pipeli
26
26
  bodyUsed?: boolean;
27
27
  bodyGenerate?: ScriptFuncOrBody<HttpGenerateBody<In, InFragment>>;
28
28
  responseGenerate?: ScriptFuncOrBody<HttpGenerateResponse<In, InFragment>>;
29
- responseErrorHandles?: {
30
- [key: HttpErrorCode]: ScriptFuncOrBody<HttpHandleError<In, InFragment, OutFragment>>;
31
- };
29
+ responseErrorHandles?: ScriptFuncOrBody<HttpHandleError<In, InFragment, OutFragment>>
30
+ | { [key: HttpErrorCode]: ScriptFuncOrBody<HttpHandleError<In, InFragment, OutFragment>>; };
32
31
  }
33
32
 
34
33
  export class FetchPipelineStep<In = PipelineStepPayload, Out = PipelineStepPayload, InFragment = In, OutFragment = Out>
@@ -112,13 +111,21 @@ export class FetchPipelineStep<In = PipelineStepPayload, Out = PipelineStepPaylo
112
111
  throw e;
113
112
  }
114
113
  });
115
- if (options.responseErrorHandles) {
116
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
117
- const defaultHandler = async (options: HttpErrorHandleOptions<In, InFragment>, _$helpers: PipelineStepHelpers, _$: PipelineStepHelpers): Promise<OutFragment> | never => {
118
- throw new UncatchableError(ERR_FETCH_ERROR, `Error[${options.$errorCode}] caught when fetch data from remote[${options.$url}].`);
119
- };
120
- const createDefaultHandler = () => defaultHandler;
121
- const getVariableNames = () => this.getErrorHandlerVariableName();
114
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
115
+ const defaultHandler = async (options: HttpErrorHandleOptions<In, InFragment>, _$helpers: PipelineStepHelpers, _$: PipelineStepHelpers): Promise<OutFragment> | never => {
116
+ throw new UncatchableError(ERR_FETCH_ERROR, `Error[${options.$errorCode}] caught when fetch data from remote[${options.$url}].`);
117
+ };
118
+ const createDefaultHandler = () => defaultHandler;
119
+ const getVariableNames = () => this.getErrorHandlerVariableName();
120
+ if (typeof options.responseErrorHandles === 'string' || typeof options.responseErrorHandles === 'function') {
121
+ this._responseErrorHandleFunc = Utils.createAsyncFunction(options.responseErrorHandles, {
122
+ createDefault: createDefaultHandler, getVariableNames,
123
+ error: (e: Error) => {
124
+ this.getLogger().error(`Failed on create function for response error handler, snippet is [${options.responseErrorHandles}].`);
125
+ throw e;
126
+ }
127
+ });
128
+ } else if (options.responseErrorHandles != null) {
122
129
  const handlers: Record<HttpErrorCode, HttpHandleError<In, InFragment, OutFragment>> = Object.keys(options.responseErrorHandles).reduce((handlers, status) => {
123
130
  handlers[status] = Utils.createAsyncFunction(options.responseErrorHandles[status], {
124
131
  createDefault: createDefaultHandler, getVariableNames,