Skip to content

Commit 3a43a3b

Browse files
committed
don't error if user is already on the grafana team
1 parent a20b86b commit 3a43a3b

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/main/scala/App.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ object App extends cask.MainRoutes:
150150
yield ()
151151
result.fold(
152152
errorMsg =>
153-
scribe.error(errorMsg); cask.Response(errorMsg)
153+
scribe.error(errorMsg); cask.Response(errorMsg, statusCode = 500)
154154
,
155155
_ => cask.Response("OK - Event processed successfully")
156156
)

src/main/scala/Grafana.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import io.circe.syntax.*
22
import io.circe.{ Decoder, Encoder }
33
import sttp.client4.*
4+
import sttp.client4.ResponseException.UnexpectedStatusCode
45
import sttp.client4.circe.*
56

67
object Grafana:
@@ -35,6 +36,11 @@ object Grafana:
3536
.response(asJson[GrafanaMessageResponse])
3637
.send(backend)
3738
.body
39+
.left.flatMap {
40+
case e: UnexpectedStatusCode[?] if e.body.toString.contains("User is already added to this team") =>
41+
Right(GrafanaMessageResponse("User is already added to this team"))
42+
case e => Left(e)
43+
}
3844

3945
case class GrafanaOrgResponse(id: Int, name: String) derives Decoder
4046

0 commit comments

Comments
 (0)