-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |