fiftyone.pipeline.cloudrequestengine 4.3.3 → 4.3.4

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/cloudEngine.js CHANGED
@@ -99,29 +99,30 @@ class CloudEngine extends Engine {
99
99
  const engine = this;
100
100
 
101
101
  return engine.ready().then(function () {
102
+
102
103
  let cloudData = flowData.get('cloud').get('cloud');
103
104
 
104
105
  cloudData = JSON.parse(cloudData);
106
+ const result = {};
105
107
 
106
- if (cloudData.device && cloudData.device[engine.dataKey] === null) {
107
- flowData.pipeline.log('warn', engine.dataKey + " not populated. " +
108
- cloudData.device[engine.dataKey + 'nullreason'] !== null ? cloudData.device[engine.dataKey + 'nullreason'] : "" +
108
+ if (cloudData && cloudData[engine.dataKey] === null) {
109
+ flowData.pipeline.log('error', engine.dataKey + " not populated. " +
110
+ cloudData[engine.dataKey + 'nullreason'] !== null ? cloudData[engine.dataKey + 'nullreason'] : "" +
109
111
  "\n" + "This may be because the provided API key is not authorised for " + engine.dataKey + " queries.");
110
- }
112
+ }
113
+ else {
111
114
 
112
115
  // Loop over cloudData.device properties to check if they have a value
113
-
114
- const result = {};
115
-
116
- Object.entries(cloudData[engine.dataKey]).forEach(function ([key, value]) {
117
- result[key] = new AspectPropertyValue();
118
-
119
- if (cloudData[engine.dataKey][key + 'nullreason']) {
120
- result[key].noValueMessage = cloudData[engine.dataKey][key + 'nullreason'];
121
- } else {
122
- result[key].value = value;
123
- }
124
- });
116
+ Object.entries(cloudData[engine.dataKey]).forEach(function ([key, value]) {
117
+ result[key] = new AspectPropertyValue();
118
+
119
+ if (cloudData[engine.dataKey][key + 'nullreason']) {
120
+ result[key].noValueMessage = cloudData[engine.dataKey][key + 'nullreason'];
121
+ } else {
122
+ result[key].value = value;
123
+ }
124
+ });
125
+ }
125
126
 
126
127
  const data = new AspectDataDictionary(
127
128
  {
@@ -24,6 +24,7 @@ class CloudRequestError extends Error {
24
24
  constructor(message, responseHeaders, httpStatusCode){
25
25
  super(message);
26
26
  this.name = this.constructor.name
27
+ this.errorMessage = message;
27
28
  this.responseHeaders = responseHeaders;
28
29
  this.httpStatusCode = httpStatusCode;
29
30
  // This clips the constructor invocation from the stack trace.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fiftyone.pipeline.cloudrequestengine",
3
- "version": "4.3.3",
3
+ "version": "4.3.4",
4
4
  "description": "Cloud request engine for the 51Degrees Pipeline API",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -20,8 +20,8 @@
20
20
  "jest": "^24.9.0"
21
21
  },
22
22
  "dependencies": {
23
- "fiftyone.pipeline.core": "^4.3.3",
24
- "fiftyone.pipeline.engines": "^4.3.3"
23
+ "fiftyone.pipeline.core": "^4.3.4",
24
+ "fiftyone.pipeline.engines": "^4.3.4"
25
25
  },
26
26
  "contributors": [
27
27
  "Filip Hnízdo <filip@octophin.com> (https://octophindigital.com/)",
@@ -59,15 +59,12 @@ const flowData = pipeline.createFlowData();
59
59
  // Check that if an invalid resource key is used, a correct error
60
60
  // message will be returned and stored in flowData.errors
61
61
  test('missing property service - invalid resource key', done => {
62
+ pipeline.suppressProcessExceptions = true;
62
63
  flowData.process().then(function () {
63
64
  var errorFound = false;
64
- flowData.errors.CloudEngineBase.forEach(function (errors) {
65
- errors.forEach(function (error) {
66
- errorFound = errorFound ||
67
- (error.message.includes(testResourceKey) &&
68
- error.message.includes('not a valid resource key'));
69
- });
70
- });
65
+ error = flowData.errors.CloudEngineBase[0];
66
+ errorFound = error.message.includes(testResourceKey) &&
67
+ error.message.includes('not a valid resource key');
71
68
  expect(errorFound).toBe(true);
72
69
 
73
70
  done();
@@ -81,7 +81,6 @@ test('custom end point - default value', done => {
81
81
  // Check that values from the http response are populated in the
82
82
  // error object.
83
83
  test('HTTP data set in error', done => {
84
- let errorThrown = false;
85
84
 
86
85
  let engine = new CloudRequestEngine({
87
86
  resourceKey: testResourceKey
@@ -90,24 +89,22 @@ test('HTTP data set in error', done => {
90
89
  const builder = new PipelineBuilder();
91
90
  const pipeline = builder.add(engine).build();
92
91
  const flowData = pipeline.createFlowData();
93
-
94
- // When an error occurs, check that the expected values are populated.
92
+ let expectedError = '\'' + testResourceKey + '\' is not a valid resource key.';
93
+
94
+ // When an error occurs, check that the message is logged.
95
95
  pipeline.on('error', (e) => {
96
- expect(e).toBeDefined();
97
- expect(e.message).toBeDefined();
98
- let expectedError = '\'' + testResourceKey + '\' is not a valid resource key.';
99
- expect(e.message[0].message).toEqual(expectedError);
100
- expect(e.message[0].httpStatusCode).toEqual(400);
101
- expect(e.message[0].responseHeaders.etag).toBeDefined();
102
- errorThrown = true;
96
+ expect(e).toBeDefined();
97
+ done();
103
98
  });
104
99
 
105
- // Make sure that the expected error was thrown.
106
100
  flowData.process().then(function () {
107
- expect(errorThrown).toBe(true);
108
101
  done();
102
+ }).catch((e) => {
103
+ // When an error occurs, check that the expected values are populated.
104
+ expect(e[0].errorMessage.indexOf(expectedError) !== -1).toBe(true);
105
+ expect(e[0].httpStatusCode).toEqual(400);
106
+ expect(e[0].responseHeaders.etag).toBeDefined();
109
107
  });
110
-
111
108
  });
112
109
 
113
110
  /**