From 5e4c6cc627b1bc9c71aee28a948c8099c5dd1835 Mon Sep 17 00:00:00 2001 From: tzugen Date: Fri, 11 Jun 2021 10:24:21 +0200 Subject: [PATCH] I made currentApiVersion nullable here two commits ago while testing, but it doesn't need to be. Also update some comments --- .../moire/ultrasonic/api/subsonic/ApiVersionCheckWrapper.kt | 6 +++--- .../kotlin/org/moire/ultrasonic/api/subsonic/Extensions.kt | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/ApiVersionCheckWrapper.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/ApiVersionCheckWrapper.kt index a30623aa..d2da7070 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/ApiVersionCheckWrapper.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/ApiVersionCheckWrapper.kt @@ -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 { @@ -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) { diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/Extensions.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/Extensions.kt index 61b310bc..666dbcf1 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/Extensions.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/Extensions.kt @@ -36,7 +36,7 @@ fun Response.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 Response.throwOnFailure(): Response { } } +/** + * 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.falseOnFailure(): Boolean { return (this.isSuccessful && this.body()!!.status === SubsonicResponse.Status.OK) }