Jason Inbody
07/18/2021, 2:28 AMfinUser.loginUser(email = email, password = hashedPassword,
onCompletion = {rspObj -> loginUserRsp(response = rspObj)},
onError = {rspObj -> loginUserError(response = rspObj) })
Then
public fun loginUser(email: String, password: String,
onCompletion: (MutableMap<String,Any>) -> Unit,
onError: (MutableMap<String,Any>) -> Unit){
this.finApi.updateUserToken(email = email, password = password,
onCompletion = onCompletion, onError = onError)
}
Then
public fun updateUserToken(email: String, password: String,
onCompletion: (MutableMap<String,Any>) -> Unit,
onError: (MutableMap<String,Any>) -> Unit){
val jsonBody = """{"email": "$email", "username": "$email", "password": "$password"}"""
this.postRequest(url = this.userLogin, header = this.header, jsonBody = jsonBody,
onCompletion = onCompletion, onError = onError)
}
to
private fun postRequest(url: String, header: Header, jsonBody: String,
onCompletion: (MutableMap<String,Any>) -> Unit,
onError: (MutableMap<String,Any>) -> Unit){
var request = <http://Fuel.post|Fuel.post>(url).body(jsonBody).header(header.content, header.contentValue)
if(header.authorizationValue != ""){
request.header(header.authorization, header.authorizationValue)
}
request.responseString { request, response, result ->
responseHandle(request = request, response = response, result = result,
onCompletion = onCompletion, onError = onError) }
}
And then I get success
private fun responseHandle(request: Request,
response: Response,
result: Result<String, FuelError>,
onCompletion: (MutableMap<String,Any>) -> Unit,
onError: (MutableMap<String,Any>) -> Unit){
when (result) {
is Result.Failure -> {
onError(Klaxon().parse<MutableMap<String, Any>>(response.responseMessage)!!)
}
is Result.Success -> {
onCompletion(Klaxon().parse<MutableMap<String, Any>>(response.responseMessage)!!)
}
}
}
But my breakpoint never hits here
fun loginUserRsp(response: MutableMap<String, Any>){
print(response)
}
It looks right... but I'm pretty new to kotlin EDIT: Nvm found the issue Klaxon().parse<MutableMap<String, Any>>(response.responseMessage)!!
wasn't doing what i thought it was