Skip to content

Commit e968685

Browse files
authored
Merge pull request #42 from haroldadmin/fixes/handle-unsupported-types
Handle unsupported response types gracefully
2 parents 16cc117 + f02cc37 commit e968685

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main/kotlin/com/haroldadmin/cnradapter/NetworkResponseAdapterFactory.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,20 @@ class NetworkResponseAdapterFactory : CallAdapter.Factory() {
1111

1212
override fun get(returnType: Type, annotations: Array<Annotation>, retrofit: Retrofit): CallAdapter<*, *>? {
1313

14-
check(returnType is ParameterizedType) { "$returnType must be parameterized. Raw types are not supported" }
14+
if (returnType !is ParameterizedType) {
15+
// returnType must be parameterized. Raw types are not supported
16+
return null
17+
}
1518

1619
val containerType = getParameterUpperBound(0, returnType)
1720
if (getRawType(containerType) != NetworkResponse::class.java) {
1821
return null
1922
}
2023

21-
check(containerType is ParameterizedType) { "$containerType must be parameterized. Raw types are not supported" }
24+
if (containerType !is ParameterizedType) {
25+
// containerType must be parameterized. Raw types are not supported
26+
return null
27+
}
2228

2329
val (successBodyType, errorBodyType) = containerType.getBodyTypes()
2430
val errorBodyConverter = retrofit.nextResponseBodyConverter<Any>(null, errorBodyType, annotations)

0 commit comments

Comments
 (0)