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

Allow WebApplicationExceptions in VertexResource #367

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -572,6 +572,8 @@ private Response getVertexEdges(String graphName, String vertexId, String direct
final JSONObject error = generateErrorObjectJsonFail(ex);
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(error).build());
} catch (WebApplicationException wae) {
logger.error(wae);

throw wae;
} catch (Exception re) {
logger.error(re);
Expand Down Expand Up @@ -726,20 +728,22 @@ private Response postVertex(final String graphName, final String id, final boole
}

this.resultObject.put(Tokens.QUERY_TIME, sh.stopWatch());
} catch (JSONException ex) {
rag.tryRollback();
} catch (WebApplicationException wae) {
logger.error(wae);

throw wae;
} catch (JSONException ex) {
logger.error(ex);

JSONObject error = generateErrorObjectJsonFail(ex);
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(error).build());
} catch (Exception re) {
rag.tryRollback();

logger.error(re);

JSONObject error = generateErrorObject(re.getMessage(), re);
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(error).build());
} finally {
safeRollback(rag);
}

return Response.ok(this.resultObject).build();
Expand Down Expand Up @@ -844,20 +848,22 @@ private Response putVertex(final String graphName, final String id, final boolea
}

this.resultObject.put(Tokens.QUERY_TIME, sh.stopWatch());
} catch (JSONException ex) {
rag.tryRollback();
} catch (WebApplicationException wae) {
logger.error(wae);

throw wae;
} catch (JSONException ex) {
logger.error(ex);

JSONObject error = generateErrorObjectJsonFail(ex);
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(error).build());
} catch (Exception re) {
rag.tryRollback();

logger.error(re);

JSONObject error = generateErrorObject(re.getMessage(), re);
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(error).build());
} finally {
safeRollback(rag);
}

return Response.ok(this.resultObject).build();
Expand Down Expand Up @@ -898,31 +904,45 @@ public Response deleteVertex(@PathParam("graphname") String graphName, @PathPara
logger.info(msg);

JSONObject error = generateErrorObject(msg);

throw new WebApplicationException(Response.status(Status.NOT_FOUND).entity(error).build());
}

rag.tryCommit();
this.resultObject.put(Tokens.QUERY_TIME, sh.stopWatch());
} catch (JSONException ex) {

rag.tryRollback();
} catch (WebApplicationException wae) {
logger.error(wae);

throw wae;
} catch (JSONException ex) {
logger.error(ex);

final JSONObject error = generateErrorObjectJsonFail(ex);
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(error).build());
} catch (Exception re) {

rag.tryRollback();

logger.error(re);

final JSONObject error = generateErrorObject(re.getMessage(), re);
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(error).build());
} finally {
safeRollback(rag);
}

return Response.ok(this.resultObject).build();
}

/**
* Calls {@link RexsterApplicationGraph#tryRollback()} on the supplied parameter.
* Swallows any {@link java.lang.Throwable} produced by {@code tryRollback} after
* logging the exception at the {@code WARN} severity level. This method always
* returns and never throws, even if it fails.
*/
private static void safeRollback(RexsterApplicationGraph rag) {
try {
rag.tryRollback();
} catch (Throwable t) {
logger.warn("Unable to rollback graph transaction", t);
}
}

private static String[] getLabelsFromRequest(JSONObject theRequestObject) {
Expand Down