Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if parsing response as JSON fails, include the raw response in error log #33

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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