Skip to content

Commit 478b2d5

Browse files
committed
404 should be ignored in catch(() -> T) too
1 parent 7e33a6a commit 478b2d5

File tree

7 files changed

+11
-11
lines changed

7 files changed

+11
-11
lines changed

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientPlayerAPI.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ClientPlayerAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
3939
fun getDevices(): SpotifyRestAction<List<Device>> {
4040
return toAction(Supplier {
4141
get(EndpointBuilder("/me/player/devices").toString()).toInnerObject<List<Device>>(
42-
"devices", api
42+
"devices"
4343
)
4444
})
4545
}

src/main/kotlin/com/adamratzman/spotify/endpoints/public/ArtistsAPI.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class ArtistsAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
117117
"country",
118118
market.name
119119
).toString()
120-
).toInnerArray<Track>("tracks", api)
120+
).toInnerArray<Track>("tracks")
121121
})
122122
}
123123

src/main/kotlin/com/adamratzman/spotify/endpoints/public/BrowseAPI.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ class BrowseAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
4141
fun getAvailableGenreSeeds(): SpotifyRestAction<List<String>> {
4242
return toAction(Supplier {
4343
get(EndpointBuilder("/recommendations/available-genre-seeds").toString()).toInnerArray<String>(
44-
"genres",
45-
api
44+
"genres"
4645
)
4746
})
4847
}

src/main/kotlin/com/adamratzman/spotify/models/Users.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ data class SpotifyPublicUser(
7272
data class Followers(
7373
val href: String?,
7474
@Json(name = "total") private val _total: Int,
75-
@Transient val total: Int = _total ?: -1
75+
@Transient val total: Int = _total
7676
)

src/main/kotlin/com/adamratzman/spotify/models/serialization/SerializationUtils.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,22 @@ internal inline fun <reified T> String.toCursorBasedPagingObject(
126126
}
127127
}
128128

129-
internal inline fun <reified T> String.toInnerObject(innerName: String, api: SpotifyAPI): T {
129+
internal inline fun <reified T> String.toInnerObject(innerName: String): T {
130130
val map = fromJsonMap<String, T>(
131131
String::class.java,
132132
T::class.java,
133133
this)!!
134134

135-
return map[innerName]!!
135+
return map[innerName] ?: error("Inner object with name $innerName doesn't exist in $map")
136136
}
137137

138-
internal inline fun <reified T> String.toInnerArray(innerName: String, api: SpotifyAPI): List<T> {
138+
internal inline fun <reified T> String.toInnerArray(innerName: String): List<T> {
139139
val map = fromJsonMap<String, Array<T>>(
140140
String::class.java,
141141
Array<T>::class.java,
142142
this)!!
143143

144-
return map[innerName]!!.toList()
144+
return (map[innerName] ?: error("Inner object with name $innerName doesn't exist in $map")).toList()
145145
}
146146

147147
private fun <K, V> fromJsonMap(keyType: Type, valueType: Type, json: String): Map<K, V>? {

src/main/kotlin/com/adamratzman/spotify/utils/MiscUtils.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ internal fun <T> catch(function: () -> T): T? {
1010
return try {
1111
function()
1212
} catch (e: BadRequestException) {
13-
if (e.statusCode != 400) throw e // we should only ignore the exception if it's a bad request (400)
13+
if (e.statusCode !in listOf(400, 404)) throw e
14+
// we should only ignore the exception if it's 400 or 404. Otherwise, it's a larger issue
1415
null
1516
}
1617
}

src/test/kotlin/com/adamratzman/spotify/utilities/HttpConnectionTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class HttpConnectionTests : Spek({
8080
}
8181

8282
describe("delete request") {
83-
val (response, body) = HttpConnection(
83+
val (response, _) = HttpConnection(
8484
"https://httpbin.org/delete?query=string",
8585
HttpRequestMethod.DELETE,
8686
null,

0 commit comments

Comments
 (0)