From 8cec401ec010f4128cdcd6581dcd6743080387d4 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 1 Jun 2017 12:41:38 +0200 Subject: [PATCH] [New] Added methods to ResponseUtil --- .../java/li/strolch/rest/helper/ResponseUtil.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/helper/ResponseUtil.java b/li.strolch.rest/src/main/java/li/strolch/rest/helper/ResponseUtil.java index 2e973bd19..a01f82f6f 100644 --- a/li.strolch.rest/src/main/java/li/strolch/rest/helper/ResponseUtil.java +++ b/li.strolch.rest/src/main/java/li/strolch/rest/helper/ResponseUtil.java @@ -91,7 +91,7 @@ public class ResponseUtil { String msg = StringHelper.DASH; String exceptionMsg = StringHelper.DASH; - if (!svcResult.isOk()) { + if (svcResult.isNok()) { msg = svcResult.getMessage(); Throwable t = svcResult.getThrowable(); if (t != null) @@ -104,6 +104,10 @@ public class ResponseUtil { response.addProperty(EXCEPTION_MSG, exceptionMsg); String json = new Gson().toJson(response); + + if (svcResult.isOk()) + return Response.ok().entity(json).type(MediaType.APPLICATION_JSON).build(); + return Response.serverError().entity(json).type(MediaType.APPLICATION_JSON).build(); } @@ -111,6 +115,14 @@ public class ResponseUtil { return toResponse(Status.INTERNAL_SERVER_ERROR, t); } + public static Response toResponse(Status status, String msg) { + JsonObject response = new JsonObject(); + response.addProperty(MSG, msg); + String json = new Gson().toJson(response); + + return Response.status(status).entity(json).type(MediaType.APPLICATION_JSON).build(); + } + public static Response toResponse(Status status, Throwable t) { JsonObject response = new JsonObject(); response.addProperty(MSG, ExceptionHelper.getExceptionMessageWithCauses(t));