diff --git a/lib/httpClient.js b/lib/httpClient.js index f25c64c..409dd07 100644 --- a/lib/httpClient.js +++ b/lib/httpClient.js @@ -54,7 +54,7 @@ class HttpClient{ }).catch(function(err){ let res = err.response; // Reject API error HTTP status code - if(res.status >= 300){ + if(typeof res !== 'undefined' && res.status >= 300){ reject( new MidtransError( `Midtrans API is returning API error. HTTP status code: ${res.status}. API response: ${JSON.stringify(res.data)}`, @@ -63,6 +63,15 @@ class HttpClient{ res ) ) + } else if(typeof res === 'undefined'){ + reject( + new MidtransError( + `Midtrans API request failed. HTTP status code not found, likely connection failure, with message: ${JSON.stringify(err.message)}`, + null, + null, + err + ) + ) } reject(err); })