Skip to content

Commit

Permalink
Refactored ManagementPortalClient to working state
Browse files Browse the repository at this point in the history
  • Loading branch information
this-Aditya committed Oct 22, 2024
1 parent 526e4aa commit d573eb2
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import java.io.IOException
import java.lang.RuntimeException
import java.net.MalformedURLException

class ManagementPortalClient constructor(
class ManagementPortalClient(
managementPortal: ServerConfig,
private val clientId: String,
private val clientSecret: String,
Expand Down Expand Up @@ -76,15 +76,15 @@ class ManagementPortalClient constructor(
if (state.userId == null) {
throw IOException("Authentication state does not contain user ID")
}
val request = client.request("api/subjects/${state.userId}") {

val request = client.prepareRequest("api/subjects/${state.userId}") {
headers {
appendAll(state.ktorHeaders)
append(HttpHeaders.Accept, APPLICATION_JSON)
}
}
.headers(state.okHttpHeaders)
.header("Accept", APPLICATION_JSON)
.build()

logger.info("Requesting subject {} with parseHeaders {}", state.userId,
state.okHttpHeaders)
state.ktorHeaders)

return handleRequest(request, parser)
}
Expand Down Expand Up @@ -168,7 +168,7 @@ class ManagementPortalClient constructor(
@Throws(IOException::class)
private suspend fun <T> handleRequest(request: HttpStatement, parser: Parser<JSONObject, T>): T {
return request.execute { response ->
val body: OAuthAccess = response.body()
val body: JSONObject = response.body()

if (response.status == HttpStatusCode.Unauthorized) {
throw AuthenticationException("QR code is invalid: $body")
Expand Down

0 comments on commit d573eb2

Please sign in to comment.