Skip to content

Commit

Permalink
add hanldling error message if httpclient get undefined response
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Kevin committed Jun 25, 2020
1 parent 5057fa5 commit 2e12e39
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/httpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`,
Expand All @@ -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);
})
Expand Down

0 comments on commit 2e12e39

Please sign in to comment.