Skip to content

Commit 26766f7

Browse files
Merge pull request #66 from acoustic-content-samples/rel4.5.5
rel4.5.5
2 parents b5dd6af + e257701 commit 26766f7

File tree

7 files changed

+64
-6
lines changed

7 files changed

+64
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 4.5.5 changes since 4.5.4
4+
- error handling
5+
- show error description when present
6+
37
### 4.5.4 changes since 4.5.3
48
- pull
59
- Fix for content pull which could cause to start infinite pulling loop

CLI/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "wchtools-cli",
33
"description": "Command line tools for Acoustic Content",
4-
"version": "4.5.4",
4+
"version": "4.5.5",
55
"keywords": [
66
"cli"
77
],
@@ -60,4 +60,4 @@
6060
"posttest": "npm run testcleanup && npm run checkcoverage",
6161
"postinstall": "node ./scripts/postinstall.js"
6262
}
63-
}
63+
}

authoring-api/lib/contentFS.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class ContentFS extends JSONItemFS {
4242
getFileName(content) {
4343
if (content && content.id) {
4444
return BaseFS.getValidFileName(content.id);
45+
} else if (content) {
46+
// when no id provided in json use path that is the file name
47+
return BaseFS.getValidFileName(content.path);
4548
}
4649
}
4750
}

authoring-api/lib/utils/utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ function getErrorFromBody (body) {
335335
if (Array.isArray(body.errors)) {
336336
body.errors.forEach(function (error, index) {
337337
messages += error.message;
338+
if(error.description) {
339+
messages += ' ' + error.description;
340+
}
338341
if (index < body.errors.length - 1) {
339342
// Add a separator if this is not the last error in the array.
340343
messages += ' ; ';

authoring-api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "wchtools-api",
33
"description": "Tools API for Acoustic Content",
4-
"version": "4.5.4",
4+
"version": "4.5.5",
55
"keywords": [
66
"api",
77
"tools"
@@ -52,4 +52,4 @@
5252
"testcleanup": "node ./test/testcleanup.js",
5353
"posttest": "npm run testcleanup && npm run checkcoverage"
5454
}
55-
}
55+
}

authoring-api/test/unit/utils.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,54 @@ describe("utils", function () {
295295
}
296296
});
297297

298+
it("should return an error based on single errors (array) property on the response body and description if present", function (done) {
299+
const TEST_ERROR_1 = "First error message used for testing.";
300+
const DESCRIPTION_1 = 'Additional description.';
301+
const testError = null;
302+
let error1 = new Error(TEST_ERROR_1);
303+
error1.description = DESCRIPTION_1;
304+
const testBody = {"errors": [error1]};
305+
const testResponse = null;
306+
const testRequestOptions = null;
307+
let error;
308+
try {
309+
const error = utils.getError(testError, testBody, testResponse, testRequestOptions);
310+
expect(error.message).to.contain(TEST_ERROR_1);
311+
expect(error.message).to.contain(DESCRIPTION_1);
312+
} catch (err) {
313+
error = err;
314+
} finally {
315+
done(error);
316+
}
317+
});
318+
319+
it("should return an error based on the errors (array) property on the response body and description if present", function (done) {
320+
const TEST_ERROR_1 = "First error message used for testing.";
321+
const TEST_ERROR_2 = "Second error message used for testing.";
322+
const DESCRIPTION_1 = 'Additional description.';
323+
const DESCRIPTION_2 = '2nd additional description.';
324+
const testError = null;
325+
let error1 = new Error(TEST_ERROR_1);
326+
error1.description = DESCRIPTION_1;
327+
let error2 = new Error(TEST_ERROR_2);
328+
error2.description = DESCRIPTION_2;
329+
const testBody = {"errors": [error1, error2]};
330+
const testResponse = null;
331+
const testRequestOptions = null;
332+
let error;
333+
try {
334+
const error = utils.getError(testError, testBody, testResponse, testRequestOptions);
335+
expect(error.message).to.contain(TEST_ERROR_1);
336+
expect(error.message).to.contain(TEST_ERROR_2);
337+
expect(error.message).to.contain(DESCRIPTION_1);
338+
expect(error.message).to.contain(DESCRIPTION_2);
339+
} catch (err) {
340+
error = err;
341+
} finally {
342+
done(error);
343+
}
344+
});
345+
298346
it("should return an error based on the errors (non-array Error) property on the response body", function (done) {
299347
const TEST_ERROR_1 = "First error message used for testing.";
300348
const testError = null;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "prod-tools",
3-
"version": "4.5.4",
3+
"version": "4.5.5",
44
"author": "Acoustic, L.P.",
55
"license": "Apache-2.0",
66
"bugs": {
@@ -28,4 +28,4 @@
2828
"install": "npm run clear && npm run npminstallall",
2929
"unit": "node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha authoring-api/test/unit/*.test.js CLI/test/unit/*.test.js -- --recursive"
3030
}
31-
}
31+
}

0 commit comments

Comments
 (0)