Skip to content

Commit

Permalink
if parsing response as JSON fails, include the raw response in error log
Browse files Browse the repository at this point in the history
This was added in order to debug e-mission/e-mission-docs#1080
  • Loading branch information
JGreenlee committed Jul 26, 2024
1 parent 72d3a4e commit 64195ea
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 64195ea

Please sign in to comment.