Skip to content

Commit

Permalink
Merge pull request #33 from JGreenlee/log_json_error
Browse files Browse the repository at this point in the history
if parsing response as JSON fails, include the raw response in error log
  • Loading branch information
shankari authored Aug 28, 2024
2 parents 72d3a4e + 64195ea commit 426d046
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/android/CommunicationHelperPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ public boolean execute(String action, JSONArray data, final CallbackContext call
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
String resultString = CommunicationHelper.pushGetJSON(ctxt, fullURL, filledMessage);
callbackContext.success(new JSONObject(resultString));
} catch (Exception e) {
callbackContext.error("While pushing/getting from server "+e.getMessage());
}
String resultString = CommunicationHelper.pushGetJSON(ctxt, fullURL, filledMessage);
callbackContext.success(new JSONObject(resultString));
} catch (JSONException e) {
callbackContext.error("While pushing/getting from server, "
+ "Response was not JSON: " + resultString
+ " Exception: "+e.getMessage());
} catch (Exception e) {
callbackContext.error("While pushing/getting from server, "+e.getMessage());
}
}
});
} catch (Exception e) {
Expand Down
5 changes: 4 additions & 1 deletion src/ios/BEMCommunicationHelperPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ - (void)pushGetJSON:(CDVInvokedUrlCommand *)command
options:kNilOptions
error: &parseError];
if (parseError != NULL) {
[self sendError:parseError callBackID:callbackId];
NSString *msg = [NSString stringWithFormat: @"Response was not JSON: %@ Error: %@",
[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding],
parseError];
[self sendError:msg callBackID:callbackId];
}
CDVPluginResult* result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
Expand Down

0 comments on commit 426d046

Please sign in to comment.