Commit 9710f391 authored by Christophe Henry's avatar Christophe Henry
Browse files

Fix #96: App crashes when trying to login to a bad URL

parent 78cf61d2
Pipeline #3984 passed with stage
in 0 seconds
# Development
* Fix [!96](https://git.feneas.org/christophehenry/freshrss-android/-/issues/96): App crashes when trying to login to a bad URL ([!98](https://git.feneas.org/christophehenry/freshrss-android/-/merge_requests/98))
# 1.3.0
## Features
......
......@@ -34,6 +34,7 @@ object Store {
}
// TODO: Test login
fun login(instance: String, user: String, password: String): Result<Unit> {
val client = OkHttpClient()
val requestBody = FormBody.Builder()
......@@ -49,10 +50,11 @@ object Store {
.build()
return runBlocking(Dispatchers.IO) {
val response = client.newCall(request).execute()
if(response.isSuccessful) {
val properties = Properties()
properties.load(response.body!!.byteStream())
runCatching(client.newCall(request)::execute).mapCatching {
if(it.isSuccessful) it.body!!.byteStream()
else throw ServerException(it)
}.mapCatching {bodyStream ->
val properties = Properties().apply {load(bodyStream)}
val account = Account(
properties.getProperty("SID", ""),
properties.getProperty("Auth", ""),
......@@ -61,9 +63,6 @@ object Store {
)
db().insertAccount(account)
service = API.get(account)
Result.success(Unit)
} else {
Result.failure(ServerException(response))
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment