Change error method signatures to reduce code verbosity

This commit is contained in:
Colin McDonald 2016-03-06 00:02:30 -05:00
parent d82ab071b6
commit 15a8239afe

View File

@ -8,21 +8,21 @@ import java.util.UUID;
@UtilityClass @UtilityClass
public class ErrorUtils { public class ErrorUtils {
public static Document createResponse(Throwable throwable) { public static String toResponseString(Throwable throwable) {
// We do this identifier thing so we can easily search logs for the exception. // We do this identifier thing so we can easily search logs for the exception.
// We can't send the stack trace to the user, so this is a good alternative. // We can't send the stack trace to the user, so this is a good alternative.
String identifier = UUID.randomUUID().toString(); String identifier = UUID.randomUUID().toString();
System.out.println("[Caught exception] Identifier=" + identifier); System.out.println("[Caught exception] Identifier=" + identifier);
throwable.printStackTrace(); throwable.printStackTrace();
return createResponse(throwable.getClass().getSimpleName(), identifier); return toResponseString(throwable.getClass().getSimpleName(), identifier);
} }
public static Document createResponse(String reason) { public static String toResponseString(String reason) {
return createResponse(reason, null); return toResponseString(reason, null);
} }
private static Document createResponse(String reason, String identifier) { private static String toResponseString(String reason, String identifier) {
Document json = new Document(); Document json = new Document();
json.put("failed", true); json.put("failed", true);
@ -32,7 +32,7 @@ public class ErrorUtils {
json.put("identifier", identifier); json.put("identifier", identifier);
} }
return json; return json.toJson();
} }
} }