From 813cd36bdff3d1923fcacce13f2d0e42d243de7a Mon Sep 17 00:00:00 2001 From: pacmano1 <44065187+pacmano1@users.noreply.github.com> Date: Fri, 10 May 2024 08:40:47 -0600 Subject: [PATCH] Create httpResponseChecker.js --- httpResponseChecker.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 httpResponseChecker.js diff --git a/httpResponseChecker.js b/httpResponseChecker.js new file mode 100644 index 0000000..14ed413 --- /dev/null +++ b/httpResponseChecker.js @@ -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 + } + } +}