File tree 1 file changed +25
-5
lines changed
1 file changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -113,8 +113,18 @@ function ConManager(baseurl, token_name) {
113
113
resp += chunk ;
114
114
} ) ;
115
115
res . on ( 'end' , ( ) => {
116
- if ( resp )
117
- resp = JSON . parse ( resp ) ;
116
+ if ( resp ) {
117
+ try {
118
+ resp = JSON . parse ( resp ) ;
119
+ } catch ( e ) {
120
+ if ( e instanceof SyntaxError ) {
121
+ resp = { 'httpErrorCode' : res . statusCode , 'code' : res . statusMessage , 'description' : resp } ;
122
+ res . statusCode = 500 ;
123
+ } else {
124
+ throw e ;
125
+ }
126
+ }
127
+ }
118
128
119
129
debug ( resp ) ;
120
130
debug ( "==================================================" ) ;
@@ -136,8 +146,18 @@ function ConManager(baseurl, token_name) {
136
146
nresp += chunk ;
137
147
} ) ;
138
148
nres . on ( 'end' , ( ) => {
139
- if ( nresp )
140
- nresp = JSON . parse ( nresp ) ;
149
+ if ( nresp ) {
150
+ try {
151
+ nresp = JSON . parse ( nresp ) ;
152
+ } catch ( e ) {
153
+ if ( e instanceof SyntaxError ) {
154
+ nresp = { 'httpErrorCode' : nres . statusCode , 'code' : nres . statusMessage , 'description' : nresp } ;
155
+ nres . statusCode = 500 ;
156
+ } else {
157
+ throw e ;
158
+ }
159
+ }
160
+ }
141
161
142
162
debug ( nresp ) ;
143
163
debug ( "==================================================" ) ;
@@ -504,6 +524,6 @@ function ConManager(baseurl, token_name) {
504
524
*/
505
525
506
526
this . login_response = { } ;
507
- } ;
527
+ }
508
528
509
529
exports . ConManager = ConManager ;
You can’t perform that action at this time.
0 commit comments