Skip to content

Commit

Permalink
fix: More Error handling, better tests
Browse files Browse the repository at this point in the history
  • Loading branch information
batje committed Mar 20, 2018
1 parent 8e10e70 commit b324ba2
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 28 deletions.
76 changes: 67 additions & 9 deletions dist/jcognos.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ var CognosRequest = (function() {
'X-XSRF-TOKEN': me.token,
'Content-Type': 'application/json; charset=UTF-8'
};
} else {
axiosCookieJarSupport(axios);
var cookieJar = new tough.CookieJar();
}
}

Expand All @@ -157,7 +160,7 @@ var CognosRequest = (function() {
.catch(function(err) {
me.log('Expected Error in initialise');

if (typeof cookieJar !== 'undefined') {
if (Utils.isNode() && typeof cookieJar !== 'undefined') {
me.log('Cookiejar', cookieJar);

var cookieurl = me.url + 'bi';
Expand Down Expand Up @@ -225,7 +228,7 @@ var CognosRequest = (function() {
me.log('get URL: ' + me.url + path);
if (!Utils.isNode) {
document.cookie = 'XSRF-TOKEN=' + me.token;
} else {
} else if (me.token) {
headers['X-XSRF-TOKEN'] = me.token;
}

Expand All @@ -246,8 +249,26 @@ var CognosRequest = (function() {
return '';
})
.catch(function(err) {
me.error('Error in Fetch of ' + path);
me.log(err);
var errormessage = '';
me.error('CognosRequest : Error in get', err);

if (typeof err.response !== 'undefined') {
if (typeof err.response.data.messages !== 'undefined') {
errormessage = err.response.data.messages[0].messageString;
} else {
errormessage = err.response.data;
}
} else {
errormessage = err.message;
}

me.error(err);

if (
errormessage != 'AAA-AUT-0011 Invalid namespace was selected.'
) {
throw errormessage;
}
});

return result;
Expand All @@ -266,7 +287,7 @@ var CognosRequest = (function() {
me.log('cookies: ', me.cookies);
if (!Utils.isNode) {
document.cookie = 'XSRF-TOKEN=' + me.token;
} else {
} else if (me.token) {
headers['X-XSRF-TOKEN'] = me.token;
}

Expand Down Expand Up @@ -334,7 +355,7 @@ var CognosRequest = (function() {
var result = {};
if (!Utils.isNode) {
document.cookie = 'XSRF-TOKEN=' + me.token;
} else {
} else if (me.token) {
headers['X-XSRF-TOKEN'] = me.token;
}

Expand Down Expand Up @@ -367,7 +388,26 @@ var CognosRequest = (function() {
return result;
})
.catch(function(err) {
me.log('CognosRequest : Error in delete', err);
var errormessage = '';
me.error('CognosRequest : Error in delete', err);

if (typeof err.response !== 'undefined') {
if (typeof err.response.data.messages !== 'undefined') {
errormessage = err.response.data.messages[0].messageString;
} else {
errormessage = err.response.data;
}
} else {
errormessage = err.message;
}

me.error(err);

if (
errormessage != 'AAA-AUT-0011 Invalid namespace was selected.'
) {
throw errormessage;
}
});
return result;
}
Expand All @@ -379,7 +419,7 @@ var CognosRequest = (function() {
var headers = {};
if (!Utils.isNode) {
document.cookie = 'XSRF-TOKEN=' + me.token;
} else {
} else if (me.token) {
headers['X-XSRF-TOKEN'] = me.token;
}

Expand All @@ -401,8 +441,26 @@ var CognosRequest = (function() {
return result;
})
.catch(function(err) {
me.log('CognosRequest : Error in put');
var errormessage = '';
me.error('CognosRequest : Error in put', err);

if (typeof err.response !== 'undefined') {
if (typeof err.response.data.messages !== 'undefined') {
errormessage = err.response.data.messages[0].messageString;
} else {
errormessage = err.response.data;
}
} else {
errormessage = err.message;
}

me.error(err);

if (
errormessage != 'AAA-AUT-0011 Invalid namespace was selected.'
) {
throw errormessage;
}
});
return result;
}
Expand Down
75 changes: 66 additions & 9 deletions dist/jcognos.js
Original file line number Diff line number Diff line change
Expand Up @@ -27904,6 +27904,8 @@ exports.inflateUndermine = inflateUndermine;
'X-XSRF-TOKEN': me.token,
'Content-Type': 'application/json; charset=UTF-8'
};
} else {
var cookieJar = new cookie.CookieJar();
}
}

Expand All @@ -27920,7 +27922,7 @@ exports.inflateUndermine = inflateUndermine;
.catch(function(err) {
me.log('Expected Error in initialise');

if (typeof cookieJar !== 'undefined') {
if (Utils.isNode() && typeof cookieJar !== 'undefined') {
me.log('Cookiejar', cookieJar);

var cookieurl = me.url + 'bi';
Expand Down Expand Up @@ -27988,7 +27990,7 @@ exports.inflateUndermine = inflateUndermine;
me.log('get URL: ' + me.url + path);
if (!Utils.isNode) {
document.cookie = 'XSRF-TOKEN=' + me.token;
} else {
} else if (me.token) {
headers['X-XSRF-TOKEN'] = me.token;
}

Expand All @@ -28009,8 +28011,26 @@ exports.inflateUndermine = inflateUndermine;
return '';
})
.catch(function(err) {
me.error('Error in Fetch of ' + path);
me.log(err);
var errormessage = '';
me.error('CognosRequest : Error in get', err);

if (typeof err.response !== 'undefined') {
if (typeof err.response.data.messages !== 'undefined') {
errormessage = err.response.data.messages[0].messageString;
} else {
errormessage = err.response.data;
}
} else {
errormessage = err.message;
}

me.error(err);

if (
errormessage != 'AAA-AUT-0011 Invalid namespace was selected.'
) {
throw errormessage;
}
});

return result;
Expand All @@ -28029,7 +28049,7 @@ exports.inflateUndermine = inflateUndermine;
me.log('cookies: ', me.cookies);
if (!Utils.isNode) {
document.cookie = 'XSRF-TOKEN=' + me.token;
} else {
} else if (me.token) {
headers['X-XSRF-TOKEN'] = me.token;
}

Expand Down Expand Up @@ -28097,7 +28117,7 @@ exports.inflateUndermine = inflateUndermine;
var result = {};
if (!Utils.isNode) {
document.cookie = 'XSRF-TOKEN=' + me.token;
} else {
} else if (me.token) {
headers['X-XSRF-TOKEN'] = me.token;
}

Expand Down Expand Up @@ -28130,7 +28150,26 @@ exports.inflateUndermine = inflateUndermine;
return result;
})
.catch(function(err) {
me.log('CognosRequest : Error in delete', err);
var errormessage = '';
me.error('CognosRequest : Error in delete', err);

if (typeof err.response !== 'undefined') {
if (typeof err.response.data.messages !== 'undefined') {
errormessage = err.response.data.messages[0].messageString;
} else {
errormessage = err.response.data;
}
} else {
errormessage = err.message;
}

me.error(err);

if (
errormessage != 'AAA-AUT-0011 Invalid namespace was selected.'
) {
throw errormessage;
}
});
return result;
}
Expand All @@ -28142,7 +28181,7 @@ exports.inflateUndermine = inflateUndermine;
var headers = {};
if (!Utils.isNode) {
document.cookie = 'XSRF-TOKEN=' + me.token;
} else {
} else if (me.token) {
headers['X-XSRF-TOKEN'] = me.token;
}

Expand All @@ -28164,8 +28203,26 @@ exports.inflateUndermine = inflateUndermine;
return result;
})
.catch(function(err) {
me.log('CognosRequest : Error in put');
var errormessage = '';
me.error('CognosRequest : Error in put', err);

if (typeof err.response !== 'undefined') {
if (typeof err.response.data.messages !== 'undefined') {
errormessage = err.response.data.messages[0].messageString;
} else {
errormessage = err.response.data;
}
} else {
errormessage = err.message;
}

me.error(err);

if (
errormessage != 'AAA-AUT-0011 Invalid namespace was selected.'
) {
throw errormessage;
}
});
return result;
}
Expand Down
Loading

0 comments on commit b324ba2

Please sign in to comment.