api: Simplify Authorization-Token extraction

This commit is contained in:
materro
2025-07-12 21:58:32 +02:00
committed by Yevhen Zadyra
parent 5d56113489
commit b927e01c9c

View File

@@ -186,21 +186,10 @@ class ApiService extends SessionSupport {
} }
private def extractAuthorizationTokenFromCookies(response: HttpResponse[_]): String = { private def extractAuthorizationTokenFromCookies(response: HttpResponse[_]): String = {
response.headers.get("Set-Cookie") match { response.cookies
case Some(cookieHeaders) => .find(_.getName == "Authorization-Token")
cookieHeaders .map(_.getValue)
.find(_.startsWith("Authorization-Token=")) .getOrElse(throw new RuntimeException("Authorization-Token cookie not found in response"))
.flatMap { header =>
header.split(";").headOption.flatMap {
_.split("=", 2) match {
case Array(_, value) => Some(value)
case _ => None
}
}
}
.getOrElse(throw new RuntimeException("Authorization-Token cookie not found in response headers"))
case None =>
throw new RuntimeException("No Set-Cookie headers found in response")
}
} }
} }