Skip to content

Commit

Permalink
Fixed thread bug for the coroutineExceptions. Created a generic funct…
Browse files Browse the repository at this point in the history
…ion to get a service for the networking client. A status code can now be found when an Api Error occurs.
  • Loading branch information
ChristianoBolla-Appwise committed Feb 10, 2023
1 parent 4725af6 commit 5038598
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ All notable changes to this project will be documented in this file.
### Improvements


## [1.4.2](https://github.com/appwise-labs/AndroidCore/releases/tag/1.4.2)

### New Features

### Bug Fixes
- Fixed thread bug for the coroutine exception

### Documentation

### Breaking

### Custom Views

### Improvements
- Created a function to get a service in a more generic way for the networking client
- A status code can now be found when an Api Error occurs.

## [1.4.1](https://github.com/appwise-labs/AndroidCore/releases/tag/1.4.1)

### Improvements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ open class BaseViewModel : ViewModel() {
private val _coroutineException = SingleLiveEvent<Throwable?>()
val coroutineException: LiveData<Throwable?> = _coroutineException
fun setCoroutineException(exception: Throwable?) {
_coroutineException.value = exception
_coroutineException.postValue(exception)
}

private val _loading = MutableLiveData<Boolean>().apply { value = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface BaseRepository {
if (response.isSuccessful) {
response.body()!!
} else {
throw Exception(parseError(response)?.toString())
throw ApiException(response.code(), parseError(response)?.toString() ?: "")
}
}
} catch (ex: UnknownHostException) {
Expand All @@ -41,4 +41,6 @@ interface BaseRepository {
null
}
}
}
}

class ApiException(val errorCode: Int, message: String) : Exception(message)
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,10 @@ abstract class BaseRestClient {
protected open fun getGson(): Gson {
return Gson()
}

/**
* Can be used to get the service in a more generic way.
*/
inline fun <reified T> getService(): T = lazy { getRetrofit.create(T::class.java) }.value

}

0 comments on commit 5038598

Please sign in to comment.