Skip to content

Commit 04a3161

Browse files
authored
Merge pull request #2476 from digma-ai/stop-reporting-refresh-failed-event
stop reporting refresh failed event Closes #2459
2 parents 3e95166 + 7a74db3 commit 04a3161

File tree

4 files changed

+56
-28
lines changed

4 files changed

+56
-28
lines changed

ide-common/src/main/kotlin/org/digma/intellij/plugin/auth/account/AbstractLoginHandler.kt

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,23 @@ abstract class AbstractLoginHandler(protected val analyticsProvider: RestAnalyti
7474
} catch (e: Throwable) {
7575

7676
warnWithException(e, "Exception in login {}, url {}", e, analyticsProvider.apiUrl)
77-
ErrorReporter.getInstance().reportError("${javaClass.simpleName}.login", e, mapOf("login trigger" to trigger))
78-
val errorMessage = ExceptionUtils.getNonEmptyMessage(e)
79-
reportAuthPosthogEvent(
80-
"login failed",
81-
this.javaClass.simpleName,
82-
trigger,
83-
mapOf("user" to user, "error" to errorMessage)
77+
ErrorReporter.getInstance().reportError(
78+
"${javaClass.simpleName}.login", e, mapOf(
79+
"login trigger" to trigger,
80+
"user" to user
81+
)
8482
)
8583

84+
withAuthManagerDebug {
85+
val errorMessage = ExceptionUtils.getNonEmptyMessage(e)
86+
reportAuthPosthogEvent(
87+
"login failed",
88+
this.javaClass.simpleName,
89+
trigger,
90+
mapOf("user" to user, "error" to errorMessage)
91+
)
92+
}
93+
8694
LoginResult(false, null, ExceptionUtils.getNonEmptyMessage(e))
8795
}
8896
}
@@ -128,18 +136,29 @@ abstract class AbstractLoginHandler(protected val analyticsProvider: RestAnalyti
128136

129137
} catch (e: Throwable) {
130138
warnWithException(e, "Exception in refresh {}", e)
131-
ErrorReporter.getInstance().reportError("${javaClass.simpleName}.refresh", e, mapOf("refresh trigger" to trigger))
132-
val errorMessage = ExceptionUtils.getNonEmptyMessage(e)
133-
reportAuthPosthogEvent(
134-
"refresh token failed", this.javaClass.simpleName, trigger, mapOf(
135-
"error" to errorMessage,
139+
ErrorReporter.getInstance().reportError(
140+
"${javaClass.simpleName}.refresh", e, mapOf(
141+
"refresh trigger" to trigger,
136142
"account.id" to account.id,
137143
"accessTokenHash" to credentials.accessTokenHash(),
138144
"refreshTokenHash" to credentials.refreshTokenHash(),
139145
"expirationDate" to credentials.getExpirationTimeAsDate()
140146
)
141147
)
142148

149+
withAuthManagerDebug {
150+
val errorMessage = ExceptionUtils.getNonEmptyMessage(e)
151+
reportAuthPosthogEvent(
152+
"refresh token failed", this.javaClass.simpleName, trigger, mapOf(
153+
"error" to errorMessage,
154+
"account.id" to account.id,
155+
"accessTokenHash" to credentials.accessTokenHash(),
156+
"refreshTokenHash" to credentials.refreshTokenHash(),
157+
"expirationDate" to credentials.getExpirationTimeAsDate()
158+
)
159+
)
160+
}
161+
143162
val authenticationException = ExceptionUtils.findCause(AuthenticationException::class.java, e)
144163
if (authenticationException != null) {
145164
throw e

ide-common/src/main/kotlin/org/digma/intellij/plugin/auth/account/CentralizedLoginHandler.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,16 @@ class CentralizedLoginHandler(analyticsProvider: RestAnalyticsProvider) : Abstra
9494

9595
warnWithException(e, "Exception in loginOrRefresh {}, url {}", e, analyticsProvider.apiUrl)
9696
ErrorReporter.getInstance().reportError("${javaClass.simpleName}.loginOrRefresh", e, mapOf("loginOrRefresh trigger" to trigger))
97-
val errorMessage = ExceptionUtils.getNonEmptyMessage(e)
98-
reportAuthPosthogEvent(
99-
"loginOrRefresh failed",
100-
this.javaClass.simpleName,
101-
trigger,
102-
mapOf("error" to errorMessage)
103-
)
97+
98+
withAuthManagerDebug {
99+
val errorMessage = ExceptionUtils.getNonEmptyMessage(e)
100+
reportAuthPosthogEvent(
101+
"loginOrRefresh failed",
102+
this.javaClass.simpleName,
103+
trigger,
104+
mapOf("error" to errorMessage)
105+
)
106+
}
104107

105108
//if got exception here then we probably can't refresh,logout, user will be redirected to login,
106109
// throw the exception to report it

ide-common/src/main/kotlin/org/digma/intellij/plugin/auth/account/LocalLoginHandler.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,16 @@ class LocalLoginHandler(analyticsProvider: RestAnalyticsProvider) : AbstractLogi
129129

130130
warnWithException(e, "Exception in loginOrRefresh {}, url {}", e, analyticsProvider.apiUrl)
131131
ErrorReporter.getInstance().reportError("${javaClass.simpleName}.loginOrRefresh", e, mapOf("loginOrRefresh trigger" to trigger))
132-
val errorMessage = ExceptionUtils.getNonEmptyMessage(e)
133-
reportAuthPosthogEvent(
134-
"loginOrRefresh failed",
135-
this.javaClass.simpleName,
136-
trigger,
137-
mapOf("error" to errorMessage)
138-
)
132+
133+
withAuthManagerDebug {
134+
val errorMessage = ExceptionUtils.getNonEmptyMessage(e)
135+
reportAuthPosthogEvent(
136+
"loginOrRefresh failed",
137+
this.javaClass.simpleName,
138+
trigger,
139+
mapOf("error" to errorMessage)
140+
)
141+
}
139142

140143
//if got exception here it may be from refresh or login, in both cases delete the current account
141144
//and login again

ide-common/src/main/kotlin/org/digma/intellij/plugin/auth/account/LoginHandler.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.digma.intellij.plugin.analytics.RestAnalyticsProvider
88
import org.digma.intellij.plugin.auth.NoOpLoginHandler
99
import org.digma.intellij.plugin.auth.credentials.DigmaCredentials
1010
import org.digma.intellij.plugin.auth.reportAuthPosthogEvent
11+
import org.digma.intellij.plugin.auth.withAuthManagerDebug
1112
import org.digma.intellij.plugin.common.ExceptionUtils
1213
import org.digma.intellij.plugin.errorreporting.ErrorReporter
1314
import org.digma.intellij.plugin.log.Log
@@ -112,8 +113,10 @@ interface LoginHandler {
112113
} catch (e: Throwable) {
113114
warnWithException(e, "Exception in logout {}, trigger {}", e, trigger)
114115
ErrorReporter.getInstance().reportError("${javaClass.simpleName}.logout", e, mapOf("logout trigger" to trigger))
115-
val errorMessage = ExceptionUtils.getNonEmptyMessage(e)
116-
reportAuthPosthogEvent("logout failed", this.javaClass.simpleName, trigger, mapOf("error" to errorMessage))
116+
withAuthManagerDebug {
117+
val errorMessage = ExceptionUtils.getNonEmptyMessage(e)
118+
reportAuthPosthogEvent("logout failed", this.javaClass.simpleName, trigger, mapOf("error" to errorMessage))
119+
}
117120
false
118121
}
119122
}

0 commit comments

Comments
 (0)