Skip to content

Commit

Permalink
Create httpResponseChecker.js
Browse files Browse the repository at this point in the history
  • Loading branch information
pacmano1 authored May 10, 2024
1 parent 94877d7 commit 813cd36
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions httpResponseChecker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
try {
msg = JSON.parse(msg) // we are going to reset msg to be its value in JSON here.
$c('isJSONresponse', true)
} catch (e) { // we have an empty msg or some other non-JSON response
$c('isJSONresponse', false)
}

var responseStatusLine = $('responseStatusLine');
var responseCode = parseInt(responseStatusLine.split(' ')[1], 10);

if ( responseCode == 200) { // we have an entirely successful message (note no check on isJSON, buyer beware)
$c('API_Post_OK',true)
process_results();
} else { // we either have an entirely bad post (endpoint not answering OR we have a JSON error)
if ($c('isJSONresponse') == true) { // do not retry, just collect the JSON stuff
responseStatus = SENT
bad_call_error_handler(JSON.stringify(msg))
} else { // Let's retry a few times
if (connectorMessage.getSendAttempts() <= 2) { // try a few times
responseStatus = QUEUED //
} else { // exceeded the tries
responseStatus = SENT
$c('API_Post_OK',false)
bad_call_error_handler(msg) // we have tried this post a few times, responseStatus will already be ERROR, so just send the alert
}
}
}

0 comments on commit 813cd36

Please sign in to comment.