Skip to content

Commit 598701f

Browse files
committed
fix location of errors; close #9
1 parent 852b0e6 commit 598701f

File tree

5 files changed

+73
-154
lines changed

5 files changed

+73
-154
lines changed

src/Errors.js

Lines changed: 0 additions & 106 deletions
This file was deleted.

src/Root.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = function(GedcomX){
55

66
// Extend serialization properties
77
GedcomX.Root.jsonProps.push('features','childAndParentsRelationships',
8-
'discussions', 'users', 'mergeAnalyses', 'merges');
8+
'discussions', 'users', 'mergeAnalyses', 'merges', 'errors');
99

1010
// Override init() so that we can deserialize normalized values
1111
var oldInit = GedcomX.Root.prototype.init;
@@ -18,6 +18,7 @@ module.exports = function(GedcomX){
1818
this.setUsers(json.users);
1919
this.setMergeAnalyses(json.mergeAnalyses);
2020
this.setMerges(json.merges);
21+
this.setErrors(json.errors);
2122
}
2223
};
2324

@@ -249,4 +250,42 @@ module.exports = function(GedcomX){
249250
return this.merges || [];
250251
};
251252

253+
/**
254+
* Get the errors
255+
*
256+
* @function getMerges
257+
* @instance
258+
* @memberof Root
259+
* @return {Error[]}
260+
*/
261+
GedcomX.Root.prototype.getErrors = function(){
262+
return this.errors || [];
263+
};
264+
265+
/**
266+
* Set the errors
267+
*
268+
* @function getMerges
269+
* @instance
270+
* @memberof Root
271+
* @param {Error[]} errors
272+
* @returns {Root} this
273+
*/
274+
GedcomX.Root.prototype.setErrors = function(errors){
275+
return this._setArray(errors, 'errors', 'addError');
276+
};
277+
278+
/**
279+
* Add a errors
280+
*
281+
* @function getMerges
282+
* @instance
283+
* @memberof Root
284+
* @param {Error} error
285+
* @returns {Root} this
286+
*/
287+
GedcomX.Root.prototype.addError = function(error){
288+
return this._arrayPush(error, 'errors', GedcomX.Error);
289+
};
290+
252291
};

src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module.exports = function(GedcomX){
1111
require('./Discussion')(GedcomX);
1212
require('./DiscussionReference')(GedcomX);
1313
require('./Error')(GedcomX);
14-
require('./Errors')(GedcomX);
1514
require('./FeatureSet')(GedcomX);
1615
require('./FeedbackInfo')(GedcomX);
1716
require('./MatchInfo')(GedcomX);

test/Errors.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

test/Root.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,37 @@ describe('Root GedcomX property extensions', function(){
293293

294294
});
295295

296+
describe('errors', function(){
297+
298+
var json = {
299+
"errors" : [ {
300+
"code" : 401,
301+
"message" : "Unable to read tf person.",
302+
"stacktrace" : "GET http://tf.prod.us-east-1.prod.fslocal.org/tf/person/KWC8-LKC?oneHops=none returned a response status of 401 Unauthorized:\n{\n\"401\": \"Unauthorized\"\n}"
303+
} ]
304+
};
305+
306+
it('Create with JSON', function(){
307+
test(GedcomX(json));
308+
});
309+
310+
it('Build', function(){
311+
test(GedcomX().addError(new GedcomX.Error(json.errors[0])));
312+
});
313+
314+
it('toJSON', function(){
315+
assert.deepEqual(GedcomX(json).toJSON(), json);
316+
});
317+
318+
function test(gedx){
319+
assert.equal(gedx.getErrors().length, 1);
320+
var error = gedx.getErrors()[0];
321+
assert.equal(error.getCode(), json.errors[0].code);
322+
assert.equal(error.getLabel(), json.errors[0].label);
323+
assert.equal(error.getMessage(), json.errors[0].message);
324+
assert.equal(error.getStacktrace(), json.errors[0].stacktrace);
325+
}
326+
327+
});
328+
296329
});

0 commit comments

Comments
 (0)