Last active
August 25, 2020 19:38
-
-
Save Alqueraf/7fbc5946b96d67d1ec0ee54aa3251a80 to your computer and use it in GitHub Desktop.
Medium User Login Request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suspend fun userLogin(emailLoginRequest: EmailLoginRequest): User? = withContext(Dispatchers.IO) { | |
try { | |
// Email Login | |
val user = httpClient.post<User>(Endpoints.Login) { | |
body = emailLoginRequest | |
header("X-Requested-With", "XMLHttpRequest") | |
} | |
user | |
} catch (t: Throwable) { | |
// Handle Error | |
when (t) { | |
is ClientRequestException -> | |
if (t.response?.status?.value == 403) { | |
// Invalid login credentials | |
null | |
} else { | |
// Unhandled error | |
null | |
} | |
is UnresolvedAddressException -> { | |
// Internet Error | |
null | |
} | |
else -> { | |
// Unhandled error | |
null | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment