@@ -258,7 +258,7 @@ export class RequestWrapper {
258258 } catch ( e ) {
259259 // ignore the error, use the object, and tack on a warning
260260 errorBody = axiosError . data ;
261- errorBody . warning = 'body contains circular reference' ;
261+ errorBody . warning = 'Body contains circular reference' ;
262262 }
263263
264264 error . body = errorBody ;
@@ -270,14 +270,20 @@ export class RequestWrapper {
270270 if ( isAuthenticationError ( axiosError ) ) {
271271 error . message = 'Access is denied due to invalid credentials.' ;
272272 }
273-
274273 } else if ( axiosError . request ) {
275274 // The request was made but no response was received
276275 // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
277276 // 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+ }
281287 } else {
282288 // Something happened in setting up the request that triggered an Error
283289 error . message = axiosError . message ;
@@ -311,11 +317,11 @@ function parsePath(path: string, params: Object): string {
311317 */
312318function isAuthenticationError ( error : any ) : boolean {
313319 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 || { } ;
316322
317323 // handle specific error from iam service, should be relevant across platforms
318- const isIamServiceError = body . context &&
324+ const isIamServiceError : boolean = body . context &&
319325 body . context . url &&
320326 body . context . url . indexOf ( 'iam' ) > - 1 ;
321327
@@ -326,6 +332,28 @@ function isAuthenticationError(error: any): boolean {
326332 return isAuthErr ;
327333}
328334
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+
329357/**
330358 * Return true if object has a specified property that is a string
331359 * @private
0 commit comments