@@ -15,6 +15,7 @@ var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
15
15
function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
16
16
17
17
var stringify = require ( 'json-stringify' ) ;
18
+ var util = require ( 'util' ) ;
18
19
var uritemplate = require ( './lib/url-template/url-template' ) ;
19
20
var apiGateway = require ( './lib/apiGatewayCore/apiGatewayClient' ) ;
20
21
var basicCrypto = require ( './lib/basicCrypto' ) ;
@@ -34,8 +35,8 @@ sipClientFactory.newClient = function (config) {
34
35
*/
35
36
36
37
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 ;
39
40
return _regenerator2 . default . wrap ( function _callee$ ( _context ) {
40
41
while ( 1 ) {
41
42
switch ( _context . prev = _context . next ) {
@@ -74,33 +75,46 @@ sipClientFactory.newClient = function (config) {
74
75
break ;
75
76
}
76
77
77
- errorObj = new Error ( 'Error exchanging code for data: ' , response . status ) ;
78
+ errorObj = new Error ( 'Error exchanging code for data: ' + response . status ) ;
78
79
_context . next = 16 ;
79
80
break ;
80
81
81
82
case 15 :
82
83
return _context . abrupt ( 'return' , verifyAndDecrypt ( response . data ) ) ;
83
84
84
85
case 16 :
85
- _context . next = 21 ;
86
+ _context . next = 23 ;
86
87
break ;
87
88
88
89
case 18 :
89
90
_context . prev = 18 ;
90
91
_context . t0 = _context [ 'catch' ] ( 7 ) ;
91
92
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));
94
94
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 :
96
110
if ( ! errorObj ) {
97
- _context . next = 23 ;
111
+ _context . next = 25 ;
98
112
break ;
99
113
}
100
114
101
115
throw errorObj ;
102
116
103
- case 23 :
117
+ case 25 :
104
118
case 'end' :
105
119
return _context . stop ( ) ;
106
120
}
0 commit comments