Skip to content

Commit 4d97232

Browse files
authored
Merge pull request #7 from civicteam/hotfix/fix-lost-error
Hotfix: fix lost error
2 parents 29d4797 + 0b4e456 commit 4d97232

File tree

5 files changed

+3456
-2043
lines changed

5 files changed

+3456
-2043
lines changed

dist/index.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
1515
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1616

1717
var stringify = require('json-stringify');
18+
var util = require('util');
1819
var uritemplate = require('./lib/url-template/url-template');
1920
var apiGateway = require('./lib/apiGatewayCore/apiGatewayClient');
2021
var basicCrypto = require('./lib/basicCrypto');
@@ -34,8 +35,8 @@ sipClientFactory.newClient = function (config) {
3435
*/
3536

3637
var exchangeCode = function () {
37-
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(jwtToken) {
38-
var body, authHeader, contentLength, additionalParams, params, scopeRequestAuthCodePostRequest, data, errorObj, response;
38+
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(jwtToken) {
39+
var body, authHeader, contentLength, additionalParams, params, scopeRequestAuthCodePostRequest, data, errorObj, response, errorStr;
3940
return _regenerator2.default.wrap(function _callee$(_context) {
4041
while (1) {
4142
switch (_context.prev = _context.next) {
@@ -74,33 +75,46 @@ sipClientFactory.newClient = function (config) {
7475
break;
7576
}
7677

77-
errorObj = new Error('Error exchanging code for data: ', response.status);
78+
errorObj = new Error('Error exchanging code for data: ' + response.status);
7879
_context.next = 16;
7980
break;
8081

8182
case 15:
8283
return _context.abrupt('return', verifyAndDecrypt(response.data));
8384

8485
case 16:
85-
_context.next = 21;
86+
_context.next = 23;
8687
break;
8788

8889
case 18:
8990
_context.prev = 18;
9091
_context.t0 = _context['catch'](7);
9192

92-
// console.log('Civic ERROR response: ', JSON.stringify(error, null, 2));
93-
errorObj = new Error('Error exchanging code for data: ' + _context.t0.data && _context.t0.data.message);
93+
// console.log('Civic ERROR response: ', util.inspect(error));
9494

95-
case 21:
95+
errorStr = void 0;
96+
97+
if (typeof _context.t0 === 'string') {
98+
errorStr = _context.t0;
99+
} else if (_context.t0.data && _context.t0.data.message) {
100+
errorStr = _context.t0.data.message;
101+
} else if (_context.t0.data) {
102+
errorStr = _context.t0.data;
103+
} else {
104+
errorStr = util.inspect(_context.t0);
105+
}
106+
107+
errorObj = new Error('Error exchanging code for data: ' + errorStr);
108+
109+
case 23:
96110
if (!errorObj) {
97-
_context.next = 23;
111+
_context.next = 25;
98112
break;
99113
}
100114

101115
throw errorObj;
102116

103-
case 23:
117+
case 25:
104118
case 'end':
105119
return _context.stop();
106120
}

dist/test/civic.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ describe('jsRsaSign JWTToken module', function () {
163163
// read in prv key and sign token
164164
var prv_JWK = rsu.readFile("test/keys/prvJWK_Key_verify_test.bin");
165165
var prvKey = JSON.parse(prv_JWK);
166-
var token = generateToken(prvKey
166+
var token = generateToken(prvKey);
167167

168168
// read in public key in JWK format and verify token
169-
);var pub_JWK = rsu.readFile("test/keys/pubJWK_Key_verify_test.bin");
169+
var pub_JWK = rsu.readFile("test/keys/pubJWK_Key_verify_test.bin");
170170
var pub_json = JSON.parse(pub_JWK);
171171
var pubKey = rs.KEYUTIL.getKey(pub_json);
172172
// verify JWT
@@ -248,10 +248,10 @@ describe('jsRsaSign JWTToken module', function () {
248248
var allowedMethod = tokenDetails.data.method;
249249
var allowedPath = tokenDetails.data.path;
250250
assert(allowedMethod === 'POST', 'POST must be specified.');
251-
assert(allowedPath === 'scopeRequest/authCode', 'incorrect path.'
251+
assert(allowedPath === 'scopeRequest/authCode', 'incorrect path.');
252252

253253
// partner public key
254-
);var pubKey = new rs.KJUR.crypto.ECDSA({ curve: curve });
254+
var pubKey = new rs.KJUR.crypto.ECDSA({ curve: curve });
255255
pubKey.setPublicKeyHex(partner_pub_key);
256256
pubKey.isPrivate = false;
257257
pubKey.isPublic = true;

index.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

33
const stringify = require('json-stringify');
4+
const util = require('util');
45
const uritemplate = require('./lib/url-template/url-template');
56
const apiGateway = require('./lib/apiGatewayCore/apiGatewayClient');
67
const basicCrypto = require('./lib/basicCrypto');
@@ -192,18 +193,29 @@ sipClientFactory.newClient = function (config) {
192193
let data, errorObj;
193194

194195
try {
195-
196196
const response = await apiGatewayClient.makeRequest(scopeRequestAuthCodePostRequest, authType, additionalParams);
197197
// console.log('Civic response: ', JSON.stringify(response, null, 2));
198198
if (response.status != 200) {
199-
errorObj = new Error('Error exchanging code for data: ' , response.status);
199+
errorObj = new Error('Error exchanging code for data: ' + response.status);
200200
} else {
201201
return verifyAndDecrypt(response.data);
202202
}
203203

204204
} catch(error) {
205-
// console.log('Civic ERROR response: ', JSON.stringify(error, null, 2));
206-
errorObj = new Error('Error exchanging code for data: ' + error.data && error.data.message);
205+
// console.log('Civic ERROR response: ', util.inspect(error));
206+
207+
let errorStr;
208+
if (typeof error === 'string') {
209+
errorStr = error;
210+
} else if (error.data && error.data.message) {
211+
errorStr = error.data.message;
212+
} else if (error.data) {
213+
errorStr = error.data;
214+
} else {
215+
errorStr = util.inspect(error);
216+
}
217+
218+
errorObj = new Error('Error exchanging code for data: ' + errorStr);
207219
}
208220

209221
if (errorObj) {

0 commit comments

Comments
 (0)