Commit 4f6cc277 authored by Patricio Bruna's avatar Patricio Bruna

Fixed error parsing

parent a6f5009f
This diff is collapsed.
This diff is collapsed.
...@@ -5,11 +5,12 @@ ...@@ -5,11 +5,12 @@
"main": "lib/zimbra-admin-api.js", "main": "lib/zimbra-admin-api.js",
"dependencies": { "dependencies": {
"crypto-browserify": "^3.11.0", "crypto-browserify": "^3.11.0",
"jquery": "2.2.3", "jquery": "^2.2.3",
"js-zimbra": "github:zboxapp/js-zimbra#webpack", "js-zimbra": "github:zboxapp/js-zimbra#super-agent",
"merge": "^1.2.0", "merge": "^1.2.0",
"options-api": "^1.1.0", "options-api": "^1.1.0",
"sprintf-js": "^1.0.3", "sprintf-js": "^1.0.3",
"superagent": "^1.8.3",
"validate.js": "^0.9.0" "validate.js": "^0.9.0"
}, },
"devDependencies": { "devDependencies": {
......
...@@ -6,16 +6,16 @@ import Dictionary from './utils/dictionary.js'; ...@@ -6,16 +6,16 @@ import Dictionary from './utils/dictionary.js';
class Error { class Error {
constructor(err) { constructor(err) {
this.status = err.status; this.code = err.Fault.Code.Value;
this.title = err.statusText; this.extra = this.getErrorInfo(err.Fault);
this.extra = this.getErrorInfo(err.responseJSON);
} }
getErrorInfo(responseJSON) { getErrorInfo(fault) {
if (responseJSON && responseJSON.Body) { if (fault && fault.Detail) {
return { return {
'code': responseJSON.Body.Fault.Detail.Error.Code, 'code': fault.Detail.Error.Code,
'reason': responseJSON.Body.Fault.Reason.Text 'reason': fault.Reason.Text,
'trace': fault.Detail.Error.Trace
} }
} else { } else {
return {}; return {};
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
} }
describe('Basic tests', function() { describe('Basic tests', function() {
this.timeout(5000);
it('should return error object when timeout', function() { it('should return error object when timeout', function() {
let api = new ZimbraAdminApi({ let api = new ZimbraAdminApi({
'url': 'http://localhost', 'url': 'http://localhost',
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
let callback = function(err, response) { let callback = function(err, response) {
let error = api.handleError(err); let error = api.handleError(err);
expect(error.constructor.name).to.equal('Error'); expect(error.constructor.name).to.equal('Error');
expect(error.title).to.equal('Internal Server Error');
expect(error.extra.code).to.equal('account.AUTH_FAILED'); expect(error.extra.code).to.equal('account.AUTH_FAILED');
done(); done();
}; };
...@@ -50,6 +49,8 @@ ...@@ -50,6 +49,8 @@
it('return token if ok validation', function(done) { it('return token if ok validation', function(done) {
let api = new ZimbraAdminApi(auth_data); let api = new ZimbraAdminApi(auth_data);
let callback = function(err, response) { let callback = function(err, response) {
if (err) return console.error(err);
console.log(api.client);
expect(api.client.token).to.exist; expect(api.client.token).to.exist;
done(); done();
}; };
...@@ -190,6 +191,7 @@ ...@@ -190,6 +191,7 @@
let getCallback = function(err, response){ let getCallback = function(err, response){
if (err) return this.handleError(err); if (err) return this.handleError(err);
api.makeBatchRequest([getAllAccounts, getAllDomains], callback); api.makeBatchRequest([getAllAccounts, getAllDomains], callback);
done();
}; };
api.login(getCallback); api.login(getCallback);
}); });
...@@ -197,6 +199,7 @@ ...@@ -197,6 +199,7 @@
}); });
describe('Account tests', function() { describe('Account tests', function() {
this.timeout(5000);
it('should create and return an account', function(done){ it('should create and return an account', function(done){
let account_name = Date.now() + '@big.com'; let account_name = Date.now() + '@big.com';
...@@ -274,7 +277,7 @@ ...@@ -274,7 +277,7 @@
api.getAccount('pbruna@itlinux.cl', function(err, data){ api.getAccount('pbruna@itlinux.cl', function(err, data){
let account = data; let account = data;
account.setPassword('', function(err, data){ account.setPassword('', function(err, data){
expect(err.title).to.exist; expect(err).to.exist;
done(); done();
}); });
}); });
...@@ -350,6 +353,7 @@ ...@@ -350,6 +353,7 @@
}); });
describe('Domain tests', function() { describe('Domain tests', function() {
this.timeout(5000);
it('should create and return Domain', function(done){ it('should create and return Domain', function(done){
let resource_name = Date.now() + '.dev'; let resource_name = Date.now() + '.dev';
...@@ -528,6 +532,7 @@ ...@@ -528,6 +532,7 @@
}); });
describe('DistributionList tests', function() { describe('DistributionList tests', function() {
this.timeout(5000);
it('should remove DL', function(done){ it('should remove DL', function(done){
let resource_name = Date.now() + '@zboxapp.dev'; let resource_name = Date.now() + '@zboxapp.dev';
...@@ -658,6 +663,7 @@ ...@@ -658,6 +663,7 @@
}); });
describe('Grants tests', function() { describe('Grants tests', function() {
this.timeout(5000);
it('should get the Grants with null target_data', function(done) { it('should get the Grants with null target_data', function(done) {
let api = new ZimbraAdminApi(auth_data); let api = new ZimbraAdminApi(auth_data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment