I made currentApiVersion nullable here two commits ago while testing,
but it doesn't need to be. Also update some comments
This commit is contained in:
parent
24ae0d9e81
commit
5e4c6cc627
|
@ -45,7 +45,7 @@ import retrofit2.Call
|
|||
@Suppress("TooManyFunctions")
|
||||
internal class ApiVersionCheckWrapper(
|
||||
val api: SubsonicAPIDefinition,
|
||||
var currentApiVersion: SubsonicAPIVersions?,
|
||||
var currentApiVersion: SubsonicAPIVersions,
|
||||
var isRealProtocolVersion: Boolean = false
|
||||
) : SubsonicAPIDefinition by api {
|
||||
override fun getArtists(musicFolderId: String?): Call<GetArtistsResponse> {
|
||||
|
@ -328,8 +328,8 @@ internal class ApiVersionCheckWrapper(
|
|||
private fun checkVersion(expectedVersion: SubsonicAPIVersions) {
|
||||
// If it is true, it is probably the first call with this server
|
||||
if (!isRealProtocolVersion) return
|
||||
if (currentApiVersion!! < expectedVersion)
|
||||
throw ApiNotSupportedException(currentApiVersion!!)
|
||||
if (currentApiVersion < expectedVersion)
|
||||
throw ApiNotSupportedException(currentApiVersion)
|
||||
}
|
||||
|
||||
private fun checkParamVersion(param: Any?, expectedVersion: SubsonicAPIVersions) {
|
||||
|
|
|
@ -36,7 +36,7 @@ fun Response<out ResponseBody>.toStreamResponse(): StreamResponse {
|
|||
}
|
||||
|
||||
/**
|
||||
* This call wraps Subsonic API calls so their results can be checked for errors, API version, etc
|
||||
* This extension checks API call results for errors, API version, etc
|
||||
* It creates Exceptions from the results returned by the Subsonic API
|
||||
*/
|
||||
@Suppress("ThrowsCount")
|
||||
|
@ -58,6 +58,10 @@ fun <T : SubsonicResponse> Response<out T>.throwOnFailure(): Response<out T> {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This extension checks API call results for errors, API version, etc
|
||||
* @return Boolean: True if everything was ok, false if an error was found
|
||||
*/
|
||||
fun Response<out SubsonicResponse>.falseOnFailure(): Boolean {
|
||||
return (this.isSuccessful && this.body()!!.status === SubsonicResponse.Status.OK)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue