ws-process 0.3.23 → 0.3.27
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/index.js +68 -49
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { tryit } from 'ui5-lib-rc';
|
|
|
3
3
|
import randomize from 'randomatic';
|
|
4
4
|
import axios from 'axios';
|
|
5
5
|
import { cloneDeep } from 'lodash';
|
|
6
|
+
import { defined } from '@bsgp/lib-core';
|
|
6
7
|
import { ref, Loading, getRef } from './Loading-esm';
|
|
7
8
|
import {
|
|
8
9
|
storeSplittedData,
|
|
@@ -499,65 +500,81 @@ function asyncSend(msg) {
|
|
|
499
500
|
const httpMSG = removeUndefinedKeys({
|
|
500
501
|
url,
|
|
501
502
|
method: msg.method,
|
|
502
|
-
params: msg.params,
|
|
503
|
-
data: msg.data,
|
|
503
|
+
params: defined(msg.params, msg.method === 'GET' ? msg.body : undefined),
|
|
504
|
+
data: defined(msg.data, msg.method !== 'GET' ? msg.body : undefined),
|
|
504
505
|
headers: {
|
|
505
506
|
...msg.headers,
|
|
506
507
|
...headers,
|
|
507
508
|
},
|
|
508
509
|
validateStatus: () => true,
|
|
509
510
|
});
|
|
510
|
-
console.log('%csending message:', 'color:green', httpMSG);
|
|
511
|
+
console.log('%csending message:', 'color:green', httpMSG, msg);
|
|
511
512
|
|
|
512
513
|
return axios(httpMSG).catch((ex) => {
|
|
513
514
|
console.log('%conmessage(converted):', 'color:red', ex);
|
|
514
|
-
|
|
515
|
+
const processID = ex.config.headers['bsg-support-process-id'];
|
|
515
516
|
const cProcessItem = getCurrentProcessItem(
|
|
516
517
|
getState,
|
|
517
|
-
|
|
518
|
+
processID,
|
|
518
519
|
);
|
|
519
520
|
if (local.validateResponse) {
|
|
520
521
|
tryit(() => local.store.dispatch(local.validateResponse(ex, cProcessItem)));
|
|
521
522
|
}
|
|
522
|
-
local.dispatch(updateWSCount(
|
|
523
|
+
local.dispatch(updateWSCount(processID));
|
|
523
524
|
reject(ex);
|
|
525
|
+
}).then((data) => {
|
|
526
|
+
const bodyUrl = tryit(() => data.data.getBodyFromUrl === true && data.data.url);
|
|
527
|
+
if (bodyUrl) {
|
|
528
|
+
return axios({
|
|
529
|
+
url: bodyUrl,
|
|
530
|
+
}).then((bodyData) => ({
|
|
531
|
+
...data,
|
|
532
|
+
data: bodyData.data,
|
|
533
|
+
}));
|
|
534
|
+
}
|
|
535
|
+
return data;
|
|
524
536
|
}).then((data) => {
|
|
525
537
|
console.log('%cHTTP.res:', 'color:red', data);
|
|
526
|
-
const
|
|
538
|
+
const processID = tryit(() => data.headers['process-id']) || tryit(() => data.config.headers['bsg-support-process-id']);
|
|
539
|
+
|
|
527
540
|
const newData = {
|
|
528
541
|
processID,
|
|
529
542
|
body: data.data,
|
|
543
|
+
headers: data.headers,
|
|
530
544
|
statusCode: data.status,
|
|
531
545
|
};
|
|
532
546
|
const cProcessItem = getCurrentProcessItem(
|
|
533
547
|
getState,
|
|
534
548
|
processID,
|
|
535
549
|
);
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
550
|
+
|
|
551
|
+
if ([undefined, true].includes(cProcessItem.doValidateResponse)) {
|
|
552
|
+
const hasError = local.validateResponse
|
|
553
|
+
? local.store.dispatch(
|
|
554
|
+
local.validateResponse(newData, cProcessItem),
|
|
555
|
+
)
|
|
556
|
+
: false;
|
|
557
|
+
if (hasError) {
|
|
542
558
|
// reject the promise from reqHandler in runProcess
|
|
543
559
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
560
|
+
const { callback } = cProcessItem;
|
|
561
|
+
if (callback) {
|
|
562
|
+
if (callback.afterFailed) {
|
|
563
|
+
callback.afterFailed(newData);
|
|
564
|
+
}
|
|
565
|
+
if (callback.always) {
|
|
566
|
+
callback.always();
|
|
567
|
+
}
|
|
548
568
|
}
|
|
549
|
-
if (
|
|
550
|
-
|
|
569
|
+
if (cProcessItem.reject) {
|
|
570
|
+
cProcessItem.reject({
|
|
571
|
+
errorOccurred: true,
|
|
572
|
+
processID,
|
|
573
|
+
data: newData,
|
|
574
|
+
});
|
|
551
575
|
}
|
|
576
|
+
return;
|
|
552
577
|
}
|
|
553
|
-
if (cProcessItem.reject) {
|
|
554
|
-
cProcessItem.reject({
|
|
555
|
-
errorOccurred: true,
|
|
556
|
-
processID,
|
|
557
|
-
data: newData,
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
return;
|
|
561
578
|
}
|
|
562
579
|
|
|
563
580
|
const { terminate } = handleResponseHandler(
|
|
@@ -774,31 +791,33 @@ function asyncSend(msg) {
|
|
|
774
791
|
jsonResponse.processID,
|
|
775
792
|
);
|
|
776
793
|
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
local.
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
if (callback
|
|
788
|
-
callback.afterFailed
|
|
794
|
+
if ([undefined, true].includes(cProcessItem.doValidateResponse)) {
|
|
795
|
+
const hasError = local.validateResponse
|
|
796
|
+
? local.store.dispatch(
|
|
797
|
+
local.validateResponse(jsonResponse, cProcessItem),
|
|
798
|
+
)
|
|
799
|
+
: false;
|
|
800
|
+
if (hasError) {
|
|
801
|
+
// reject the promise from reqHandler in runProcess
|
|
802
|
+
|
|
803
|
+
const { callback } = cProcessItem;
|
|
804
|
+
if (callback) {
|
|
805
|
+
if (callback.afterFailed) {
|
|
806
|
+
callback.afterFailed(jsonResponse);
|
|
807
|
+
}
|
|
808
|
+
if (callback.always) {
|
|
809
|
+
callback.always();
|
|
810
|
+
}
|
|
789
811
|
}
|
|
790
|
-
if (
|
|
791
|
-
|
|
812
|
+
if (cProcessItem.reject) {
|
|
813
|
+
cProcessItem.reject({
|
|
814
|
+
errorOccurred: true,
|
|
815
|
+
processID: cProcessItem.processID,
|
|
816
|
+
data: jsonResponse,
|
|
817
|
+
});
|
|
792
818
|
}
|
|
819
|
+
return;
|
|
793
820
|
}
|
|
794
|
-
if (cProcessItem.reject) {
|
|
795
|
-
cProcessItem.reject({
|
|
796
|
-
errorOccurred: true,
|
|
797
|
-
processID: cProcessItem.processID,
|
|
798
|
-
data: jsonResponse,
|
|
799
|
-
});
|
|
800
|
-
}
|
|
801
|
-
return;
|
|
802
821
|
}
|
|
803
822
|
|
|
804
823
|
const thisCount = tryit(() => jsonResponse.body.d.results.length);
|