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