@@ -258,7 +258,7 @@ export class RequestWrapper {
258
258
} catch ( e ) {
259
259
// ignore the error, use the object, and tack on a warning
260
260
errorBody = axiosError . data ;
261
- errorBody . warning = 'body contains circular reference' ;
261
+ errorBody . warning = 'Body contains circular reference' ;
262
262
}
263
263
264
264
error . body = errorBody ;
@@ -270,14 +270,20 @@ export class RequestWrapper {
270
270
if ( isAuthenticationError ( axiosError ) ) {
271
271
error . message = 'Access is denied due to invalid credentials.' ;
272
272
}
273
-
274
273
} else if ( axiosError . request ) {
275
274
// The request was made but no response was received
276
275
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
277
276
// http.ClientRequest in node.js
278
- error . message = 'Response not received. Body of error is HTTP ClientRequest object' ;
279
- error . body = axiosError . request ;
280
-
277
+ error . message = axiosError . message ;
278
+ error . statusText = axiosError . code ;
279
+ error . body = 'Response not received - no connection was made to the service.' ;
280
+
281
+ // when a request to a private cloud instance has an ssl problem, it never connects and follows this branch of the error handling
282
+ if ( isSelfSignedCertificateError ( axiosError ) ) {
283
+ error . message = `If you're trying to call a service on ICP or Cloud Pak for Data, you ` +
284
+ `may not have a valid SSL certificate. If you need to access the service without setting that up, try using ` +
285
+ `the disableSslVerification option in your client configuration and your authentication configuration if applicable.` ;
286
+ }
281
287
} else {
282
288
// Something happened in setting up the request that triggered an Error
283
289
error . message = axiosError . message ;
@@ -311,11 +317,11 @@ function parsePath(path: string, params: Object): string {
311
317
*/
312
318
function isAuthenticationError ( error : any ) : boolean {
313
319
let isAuthErr = false ;
314
- const code = error . status ;
315
- const body = error . data ;
320
+ const code : number = error . status || null ;
321
+ const body : any = error . data || { } ;
316
322
317
323
// handle specific error from iam service, should be relevant across platforms
318
- const isIamServiceError = body . context &&
324
+ const isIamServiceError : boolean = body . context &&
319
325
body . context . url &&
320
326
body . context . url . indexOf ( 'iam' ) > - 1 ;
321
327
@@ -326,6 +332,28 @@ function isAuthenticationError(error: any): boolean {
326
332
return isAuthErr ;
327
333
}
328
334
335
+ /**
336
+ * Determine if the error is due to a bad self signed certificate
337
+ * @private
338
+ * @param {Object } error - error object returned from axios
339
+ * @returns {boolean } true if error is due to an SSL error
340
+ */
341
+ function isSelfSignedCertificateError ( error : any ) : boolean {
342
+ let result = false ;
343
+
344
+ const sslCode = 'DEPTH_ZERO_SELF_SIGNED_CERT' ;
345
+ const sslMessage = 'self signed certificate' ;
346
+
347
+ const hasSslCode = error . code === sslCode ;
348
+ const hasSslMessage = hasStringProperty ( error , 'message' ) && error . message . includes ( sslMessage ) ;
349
+
350
+ if ( hasSslCode || hasSslMessage ) {
351
+ result = true ;
352
+ }
353
+
354
+ return result ;
355
+ }
356
+
329
357
/**
330
358
* Return true if object has a specified property that is a string
331
359
* @private
0 commit comments