Search in sources :

Example 1 with H2OAbstractRuntimeException

use of water.exceptions.H2OAbstractRuntimeException in project h2o-3 by h2oai.

the class JettyHTTPD method sendErrorResponse.

public static void sendErrorResponse(HttpServletResponse response, Exception e, String uri) {
    if (e instanceof H2OFailException) {
        H2OFailException ee = (H2OFailException) e;
        H2OError error = ee.toH2OError(uri);
        Log.fatal("Caught exception (fatal to the cluster): " + error.toString());
        throw (H2O.fail(error.toString()));
    } else if (e instanceof H2OAbstractRuntimeException) {
        H2OAbstractRuntimeException ee = (H2OAbstractRuntimeException) e;
        H2OError error = ee.toH2OError(uri);
        Log.warn("Caught exception: " + error.toString());
        setResponseStatus(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        // Note: don't use Schema.schema(version, error) because we have to work at bootstrap:
        try {
            @SuppressWarnings("unchecked") String s = new H2OErrorV3().fillFromImpl(error).toJsonString();
            response.getWriter().write(s);
        } catch (Exception ignore) {
            ignore.printStackTrace();
        }
    } else {
        // make sure that no Exception is ever thrown out from the request
        H2OError error = new H2OError(e, uri);
        // some special cases for which we return 400 because it's likely a problem with the client request:
        if (e instanceof IllegalArgumentException)
            error._http_status = HttpResponseStatus.BAD_REQUEST.getCode();
        else if (e instanceof FileNotFoundException)
            error._http_status = HttpResponseStatus.BAD_REQUEST.getCode();
        else if (e instanceof MalformedURLException)
            error._http_status = HttpResponseStatus.BAD_REQUEST.getCode();
        setResponseStatus(response, error._http_status);
        Log.warn("Caught exception: " + error.toString());
        // Note: don't use Schema.schema(version, error) because we have to work at bootstrap:
        try {
            @SuppressWarnings("unchecked") String s = new H2OErrorV3().fillFromImpl(error).toJsonString();
            response.getWriter().write(s);
        } catch (Exception ignore) {
            ignore.printStackTrace();
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) H2OErrorV3(water.api.schemas3.H2OErrorV3) H2OFailException(water.exceptions.H2OFailException) H2OAbstractRuntimeException(water.exceptions.H2OAbstractRuntimeException) ServletException(javax.servlet.ServletException) H2OFailException(water.exceptions.H2OFailException) H2OAbstractRuntimeException(water.exceptions.H2OAbstractRuntimeException) MalformedURLException(java.net.MalformedURLException)

Aggregations

MalformedURLException (java.net.MalformedURLException)1 ServletException (javax.servlet.ServletException)1 H2OErrorV3 (water.api.schemas3.H2OErrorV3)1 H2OAbstractRuntimeException (water.exceptions.H2OAbstractRuntimeException)1 H2OFailException (water.exceptions.H2OFailException)1