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

Issue 325 - unify error messaging in J4pRemoteException #326

Merged
merged 1 commit into from
Jul 6, 2017
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class J4pRemoteException extends J4pException {
// JSONObject containing value of the remote error
private JSONObject errorValue;

// String containing the entire response
private JSONObject response;

/**
* Constructor for a remote exception
*
Expand All @@ -65,20 +68,21 @@ public J4pRemoteException(J4pRequest pJ4pRequest, JSONObject pJsonRespObject) {
Long statusL = statusO instanceof Long ? (Long) statusO : null;
status = statusL != null ? statusL.intValue() : 500;
request = pJ4pRequest;
response = pJsonRespObject;
errorType = (String) pJsonRespObject.get("error_type");
remoteStacktrace = (String) pJsonRespObject.get("stacktrace");
errorValue = (JSONObject) pJsonRespObject.get("error_value");
}

private static String generateErrorMessage(J4pRequest pJ4pRequest, JSONObject pJsonRespObject) {
if( pJsonRespObject.get("error") != null ) {
return (String) pJsonRespObject.get("error");
return "Error: " + (String) pJsonRespObject.get("error");
}
Object o = pJsonRespObject.get("status");
if( o != null && !(o instanceof Long)) {
return "Invalid status of type " + o.getClass().getName() + "('" + o.toString() + "') received";
}
return "Invalid response received: " + pJsonRespObject.toJSONString();
return "Invalid response received";
}

/**
Expand Down Expand Up @@ -124,8 +128,17 @@ public J4pRequest getRequest() {
*
* @return value of the remote error as JSON
*/
public JSONObject getErrorValue() {
return errorValue;
}

public JSONObject getErrorValue() {
return errorValue;
}


/**
* Get the response string, or null if unavailable
*
* @return value of the json response string
*/
public JSONObject getResponse() {
return response;
}
}