HttpErrorResponse extends HttpResponse { public static HttpErrorResponse badRequest(String msg) { return new HttpErrorResponse(BAD_REQUEST, errorCodes.BAD_REQUEST.name(), msg); } HttpErrorResponse(int code, final String errorType, final String msg); static HttpErrorResponse notFoundError(String msg); static HttpErrorResponse internalServerError(String msg); static HttpErrorResponse invalidApplicationPackage(String msg); static HttpErrorResponse outOfCapacity(String msg); static HttpErrorResponse badRequest(String msg); static HttpErrorResponse conflictWhenActivating(String msg); static HttpErrorResponse methodNotAllowed(String msg); static HttpResponse unknownVespaVersion(String message); static HttpResponse requestTimeout(String message); static HttpErrorResponse applicationLockFailure(String msg); static HttpErrorResponse parentHostNotReady(String msg); static HttpErrorResponse certificateNotReady(String msg); static HttpErrorResponse loadBalancerNotReady(String msg); @Override void render(OutputStream stream); String getContentType();  }
@Test public void testThatHttpErrorResponseIsRenderedAsJson() throws IOException { HttpErrorResponse response = HttpErrorResponse.badRequest("Error doing something"); assertThat(response.getJdiscResponse().getStatus(), is(BAD_REQUEST)); assertThat(SessionHandlerTest.getRenderedString(response), is("{\"error-code\":\"BAD_REQUEST\",\"message\":\"Error doing something\"}")); }
@Test public void testThatHttpErrorResponseProvidesCorrectErrorMessage() throws IOException { HttpErrorResponse response = HttpErrorResponse.badRequest("Error doing something"); HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(response, BAD_REQUEST, HttpErrorResponse.errorCodes.BAD_REQUEST, "Error doing something"); }