Skip to content

Commit e267235

Browse files
committed
add documentation
Signed-off-by: alperozturk <[email protected]>
1 parent 05e4e72 commit e267235

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

app/src/main/java/it/niedermann/owncloud/notes/util/ThrowableExtensions.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ package it.niedermann.owncloud.notes.util
88

99
import com.nextcloud.android.sso.api.EmptyResponse
1010

11+
/**
12+
* Extension function to detect a specific ClassCastException caused by an empty API response.
13+
*
14+
* This is used to identify cases where the API returns an empty response body,
15+
* which leads to a `ClassCastException` when attempting to deserialize it into a non-nullable type.
16+
*
17+
* In particular, when the API processes an empty Reader (e.g., no changes detected),
18+
* it may result in a `JsonSyntaxException` or similar parsing error.
19+
* This function helps to safely ignore such cases by checking if the exception
20+
* is a `ClassCastException` involving the `EmptyResponse` class.
21+
*
22+
* @return `true` if the Throwable is a ClassCastException referencing `EmptyResponse`, otherwise `false`.
23+
*/
1124
fun Throwable.isEmptyResponseCast(): Boolean {
1225
return this is ClassCastException &&
1326
(message?.contains(EmptyResponse::class.simpleName ?: "") == true)

0 commit comments

Comments
 (0)