Skip to content

Commit

Permalink
fix location of errors; close #9
Browse files Browse the repository at this point in the history
  • Loading branch information
justincy committed Nov 17, 2016
1 parent 852b0e6 commit 598701f
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 154 deletions.
106 changes: 0 additions & 106 deletions src/Errors.js

This file was deleted.

41 changes: 40 additions & 1 deletion src/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = function(GedcomX){

// Extend serialization properties
GedcomX.Root.jsonProps.push('features','childAndParentsRelationships',
'discussions', 'users', 'mergeAnalyses', 'merges');
'discussions', 'users', 'mergeAnalyses', 'merges', 'errors');

// Override init() so that we can deserialize normalized values
var oldInit = GedcomX.Root.prototype.init;
Expand All @@ -18,6 +18,7 @@ module.exports = function(GedcomX){
this.setUsers(json.users);
this.setMergeAnalyses(json.mergeAnalyses);
this.setMerges(json.merges);
this.setErrors(json.errors);
}
};

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

/**
* Get the errors
*
* @function getMerges
* @instance
* @memberof Root
* @return {Error[]}
*/
GedcomX.Root.prototype.getErrors = function(){
return this.errors || [];
};

/**
* Set the errors
*
* @function getMerges
* @instance
* @memberof Root
* @param {Error[]} errors
* @returns {Root} this
*/
GedcomX.Root.prototype.setErrors = function(errors){
return this._setArray(errors, 'errors', 'addError');
};

/**
* Add a errors
*
* @function getMerges
* @instance
* @memberof Root
* @param {Error} error
* @returns {Root} this
*/
GedcomX.Root.prototype.addError = function(error){
return this._arrayPush(error, 'errors', GedcomX.Error);
};

};
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = function(GedcomX){
require('./Discussion')(GedcomX);
require('./DiscussionReference')(GedcomX);
require('./Error')(GedcomX);
require('./Errors')(GedcomX);
require('./FeatureSet')(GedcomX);
require('./FeedbackInfo')(GedcomX);
require('./MatchInfo')(GedcomX);
Expand Down
46 changes: 0 additions & 46 deletions test/Errors.js

This file was deleted.

33 changes: 33 additions & 0 deletions test/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,37 @@ describe('Root GedcomX property extensions', function(){

});

describe('errors', function(){

var json = {
"errors" : [ {
"code" : 401,
"message" : "Unable to read tf person.",
"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}"
} ]
};

it('Create with JSON', function(){
test(GedcomX(json));
});

it('Build', function(){
test(GedcomX().addError(new GedcomX.Error(json.errors[0])));
});

it('toJSON', function(){
assert.deepEqual(GedcomX(json).toJSON(), json);
});

function test(gedx){
assert.equal(gedx.getErrors().length, 1);
var error = gedx.getErrors()[0];
assert.equal(error.getCode(), json.errors[0].code);
assert.equal(error.getLabel(), json.errors[0].label);
assert.equal(error.getMessage(), json.errors[0].message);
assert.equal(error.getStacktrace(), json.errors[0].stacktrace);
}

});

});

0 comments on commit 598701f

Please sign in to comment.