@Override public void handle(Request request, Response response) { throw new ServerException(HTTP_GONE, String.format("The web service '%s' doesn't exist anymore, please read its documentation to use alternatives", request.getPath())); }
public static void verifyRequest(WebService.Action action, Request request) { switch (request.method()) { case "GET": if (action.isPost()) { throw new ServerException(SC_METHOD_NOT_ALLOWED, "HTTP method POST is required"); } return; case "PUT": case "DELETE": throw new ServerException(SC_METHOD_NOT_ALLOWED, String.format("HTTP method %s is not allowed", request.method())); default: // Nothing to do } } }
private String hashToken(DbSession dbSession, String token) { String tokenHash = tokenGenerator.hash(token); UserTokenDto userToken = dbClient.userTokenDao().selectByTokenHash(dbSession, tokenHash); if (userToken == null) { return tokenHash; } throw new ServerException(HTTP_INTERNAL_ERROR, "Error while generating token. Please try again."); }
@Test public void should_create_exception_with_status() { ServerException exception = new ServerException(400, "error!"); assertThat(exception.httpCode()).isEqualTo(400); }
@Test public void should_create_exception_with_status_and_message() { ServerException exception = new ServerException(404, "Not found"); assertThat(exception.httpCode()).isEqualTo(404); assertThat(exception.getMessage()).isEqualTo("Not found"); } }
@Override public void handle(Request request, Response response) { throw new ServerException(HTTP_GONE, String.format("The web service '%s' doesn't exist anymore, please read its documentation to use alternatives", request.getPath())); }
public static void verifyRequest(WebService.Action action, Request request) { switch (request.method()) { case "GET": if (action.isPost()) { throw new ServerException(SC_METHOD_NOT_ALLOWED, "HTTP method POST is required"); } return; case "PUT": case "DELETE": throw new ServerException(SC_METHOD_NOT_ALLOWED, String.format("HTTP method %s is not allowed", request.method())); default: // Nothing to do } } }
private String hashToken(DbSession dbSession, String token) { String tokenHash = tokenGenerator.hash(token); UserTokenDto userToken = dbClient.userTokenDao().selectByTokenHash(dbSession, tokenHash); if (userToken == null) { return tokenHash; } throw new ServerException(HTTP_INTERNAL_ERROR, "Error while generating token. Please try again."); }