Search in sources :

Example 1 with ServerException

use of org.sonar.server.exceptions.ServerException in project sonarqube by SonarSource.

the class RemovedWebServiceHandlerTest method throw_server_exception.

@Test
public void throw_server_exception() {
    Request request = mock(Request.class);
    when(request.getPath()).thenReturn("/api/resources/index");
    try {
        RemovedWebServiceHandler.INSTANCE.handle(request, null);
        fail();
    } catch (ServerException e) {
        assertThat(e.getMessage()).isEqualTo("The web service '/api/resources/index' doesn't exist anymore, please read its documentation to use alternatives");
        assertThat(e.httpCode()).isEqualTo(410);
    }
}
Also used : ServerException(org.sonar.server.exceptions.ServerException) Request(org.sonar.api.server.ws.Request) Test(org.junit.Test)

Example 2 with ServerException

use of org.sonar.server.exceptions.ServerException in project sonarqube by SonarSource.

the class GenerateAction method hashToken.

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.");
}
Also used : ServerException(org.sonar.server.exceptions.ServerException) UserTokenDto(org.sonar.db.user.UserTokenDto)

Aggregations

ServerException (org.sonar.server.exceptions.ServerException)2 Test (org.junit.Test)1 Request (org.sonar.api.server.ws.Request)1 UserTokenDto (org.sonar.db.user.UserTokenDto)1