Skip to content

Commit

Permalink
Notify client only on 401 response from server
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-knize-sonarsource committed Jan 27, 2025
1 parent cd6990a commit 16bf750
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcClient;
import org.sonarsource.sonarlint.core.rpc.protocol.client.sync.InvalidTokenParams;
import org.sonarsource.sonarlint.core.serverapi.ServerApi;
import org.sonarsource.sonarlint.core.serverapi.exception.ForbiddenException;
import org.sonarsource.sonarlint.core.serverapi.exception.UnauthorizedException;

public class ServerConnection {

Expand Down Expand Up @@ -59,7 +59,7 @@ public <T> T withClientApiAndReturn(Function<ServerApi, T> serverApiConsumer) {
state = ConnectionState.ACTIVE;
lastNotificationTime = null;
return result;
} catch (ForbiddenException e) {
} catch (UnauthorizedException e) {
state = ConnectionState.INVALID_CREDENTIALS;
notifyClientAboutWrongTokenIfNeeded();
}
Expand All @@ -71,7 +71,7 @@ public void withClientApi(Consumer<ServerApi> serverApiConsumer) {
serverApiConsumer.accept(serverApi);
state = ConnectionState.ACTIVE;
lastNotificationTime = null;
} catch (ForbiddenException e) {
} catch (UnauthorizedException e) {
state = ConnectionState.INVALID_CREDENTIALS;
notifyClientAboutWrongTokenIfNeeded();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcClient;
import org.sonarsource.sonarlint.core.serverapi.EndpointParams;
import org.sonarsource.sonarlint.core.serverapi.ServerApi;
import org.sonarsource.sonarlint.core.serverapi.exception.ForbiddenException;
import org.sonarsource.sonarlint.core.serverapi.exception.UnauthorizedException;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doReturn;
Expand Down Expand Up @@ -152,7 +152,7 @@ void should_log_invalid_connection() {

// switch connection to invalid state
spy.withValidConnection(connectionId, api -> {
throw new ForbiddenException("401");
throw new UnauthorizedException("401");
});
// attempt to get connection
spy.withValidConnection(connectionId, api -> {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void it_should_sync_when_credentials_are_updated(SonarLintTestHarness harness) {

@SonarLintTest
void it_should_notify_client_if_invalid_token() {
var status = 403;
var status = 401;
var client = newFakeClient()
.withCredentials(CONNECTION_ID, "user", "pw")
.build();
Expand Down

0 comments on commit 16bf750

Please sign in to comment.