[New] Added methods to ResponseUtil
This commit is contained in:
parent
d8452f4cf5
commit
8cec401ec0
|
@ -91,7 +91,7 @@ public class ResponseUtil {
|
||||||
String msg = StringHelper.DASH;
|
String msg = StringHelper.DASH;
|
||||||
String exceptionMsg = StringHelper.DASH;
|
String exceptionMsg = StringHelper.DASH;
|
||||||
|
|
||||||
if (!svcResult.isOk()) {
|
if (svcResult.isNok()) {
|
||||||
msg = svcResult.getMessage();
|
msg = svcResult.getMessage();
|
||||||
Throwable t = svcResult.getThrowable();
|
Throwable t = svcResult.getThrowable();
|
||||||
if (t != null)
|
if (t != null)
|
||||||
|
@ -104,6 +104,10 @@ public class ResponseUtil {
|
||||||
response.addProperty(EXCEPTION_MSG, exceptionMsg);
|
response.addProperty(EXCEPTION_MSG, exceptionMsg);
|
||||||
|
|
||||||
String json = new Gson().toJson(response);
|
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();
|
return Response.serverError().entity(json).type(MediaType.APPLICATION_JSON).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,6 +115,14 @@ public class ResponseUtil {
|
||||||
return toResponse(Status.INTERNAL_SERVER_ERROR, t);
|
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) {
|
public static Response toResponse(Status status, Throwable t) {
|
||||||
JsonObject response = new JsonObject();
|
JsonObject response = new JsonObject();
|
||||||
response.addProperty(MSG, ExceptionHelper.getExceptionMessageWithCauses(t));
|
response.addProperty(MSG, ExceptionHelper.getExceptionMessageWithCauses(t));
|
||||||
|
|
Loading…
Reference in New Issue