Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 06ee04c

Browse files
authored
Merge pull request #3002 from wordpress-mobile/issue/20375
Fixes: try to catch exception for fun getListItems()
2 parents fdf3a12 + 186a24e commit 06ee04c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

fluxc/src/main/java/org/wordpress/android/fluxc/persistence/ListItemSqlUtils.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import com.yarolegovich.wellsql.SelectQuery
66
import com.yarolegovich.wellsql.WellSql
77
import org.wordpress.android.fluxc.model.list.ListItemModel
88
import org.wordpress.android.fluxc.persistence.WellSqlConfig.Companion.SQLITE_MAX_VARIABLE_NUMBER
9+
import org.wordpress.android.util.AppLog
10+
import org.wordpress.android.util.AppLog.T
911
import javax.inject.Inject
1012
import javax.inject.Singleton
1113

@@ -24,8 +26,19 @@ class ListItemSqlUtils @Inject constructor() {
2426

2527
/**
2628
* This function returns a list of [ListItemModel] records for the given [listId].
29+
* It catches exceptions that occur during the database query and handles them.
2730
*/
28-
fun getListItems(listId: Int): List<ListItemModel> = getListItemsQuery(listId).asModel
31+
@Suppress("TooGenericExceptionCaught")
32+
fun getListItems(listId: Int): List<ListItemModel> {
33+
return try {
34+
// Attempt to execute the query and map the result to models
35+
getListItemsQuery(listId).asModel
36+
} catch (e: Exception) {
37+
// Handle exceptions that might occur
38+
AppLog.e(T.DB, "Error fetching items for listId: $listId", e)
39+
emptyList()
40+
}
41+
}
2942

3043
/**
3144
* This function returns the number of records a list has for the given [listId].

0 commit comments

Comments
 (0)