-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhttpResponseChecker.js
29 lines (26 loc) · 1.43 KB
/
httpResponseChecker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright (c) [2024] [Diridium Technologies Inc. https://diridium.com]
try {
msg = JSON.parse(msg) // we are going to reset msg to be its value in JSON here.
$co('isJSONresponse', true)
} catch (e) { // we have an empty msg or some other non-JSON response
$co('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)
$co('API_Post_OK',true)
process_results();
} else { // we either have an entirely bad post (endpoint not answering OR we have a JSON error)
if ($co('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
$co('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
}
}
}