package valandur.webapi.handlers;

import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.handler.ErrorHandler;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.Writer;

public class CustomErrorHandler extends ErrorHandler {
    @Override
    protected void handleErrorPage(HttpServletRequest request, Writer writer, int code, String message) throws IOException {
        if (message == null)
            message= HttpStatus.getMessage(code);

        writer.write("{ code: " + code + ", message: \"" + message + "\" }");
    }
}

@@ -28,16 +28,51 @@
 dlers;%0A%0A
+import com.google.gson.JsonObject;%0A
 import o
@@ -544,75 +544,162 @@
     
-writer.write(%22%7B code: %22 + code + %22, message: %5C%22%22 + message + %22%5C%22 %7D%22
+JsonObject obj = new JsonObject();%0A        obj.addProperty(%22code%22, code);%0A        obj.addProperty(%22message%22, message);%0A        writer.write(obj.toString()
 );%0A 

Use actual json object in error handler