From 2e12e3977f39088c140297dd866c48085cb410f8 Mon Sep 17 00:00:00 2001 From: Alexander Kevin Date: Thu, 25 Jun 2020 16:22:24 +0700 Subject: [PATCH] add hanldling error message if httpclient get undefined response --- lib/httpClient.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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); })