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:
tzugen 2021-06-11 10:24:21 +02:00
parent 24ae0d9e81
commit 5e4c6cc627
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
2 changed files with 8 additions and 4 deletions

View File

@ -45,7 +45,7 @@ import retrofit2.Call
@Suppress("TooManyFunctions") @Suppress("TooManyFunctions")
internal class ApiVersionCheckWrapper( internal class ApiVersionCheckWrapper(
val api: SubsonicAPIDefinition, val api: SubsonicAPIDefinition,
var currentApiVersion: SubsonicAPIVersions?, var currentApiVersion: SubsonicAPIVersions,
var isRealProtocolVersion: Boolean = false var isRealProtocolVersion: Boolean = false
) : SubsonicAPIDefinition by api { ) : SubsonicAPIDefinition by api {
override fun getArtists(musicFolderId: String?): Call<GetArtistsResponse> { override fun getArtists(musicFolderId: String?): Call<GetArtistsResponse> {
@ -328,8 +328,8 @@ internal class ApiVersionCheckWrapper(
private fun checkVersion(expectedVersion: SubsonicAPIVersions) { private fun checkVersion(expectedVersion: SubsonicAPIVersions) {
// If it is true, it is probably the first call with this server // If it is true, it is probably the first call with this server
if (!isRealProtocolVersion) return if (!isRealProtocolVersion) return
if (currentApiVersion!! < expectedVersion) if (currentApiVersion < expectedVersion)
throw ApiNotSupportedException(currentApiVersion!!) throw ApiNotSupportedException(currentApiVersion)
} }
private fun checkParamVersion(param: Any?, expectedVersion: SubsonicAPIVersions) { private fun checkParamVersion(param: Any?, expectedVersion: SubsonicAPIVersions) {

View File

@ -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 * It creates Exceptions from the results returned by the Subsonic API
*/ */
@Suppress("ThrowsCount") @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 { fun Response<out SubsonicResponse>.falseOnFailure(): Boolean {
return (this.isSuccessful && this.body()!!.status === SubsonicResponse.Status.OK) return (this.isSuccessful && this.body()!!.status === SubsonicResponse.Status.OK)
} }