Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.shopify.checkoutkit.androiddemo.cart.data

class CartOperationException(message: String) : RuntimeException(message)
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CartRepository(

if (cart == null) {
val errors = cartCreate?.userErrors?.joinToString { "${it.field} - ${it.message}" }
throw RuntimeException("Failed to create cart, $errors")
throw CartOperationException("Failed to create cart, $errors")
}

Timber.i("Cart created with checkout URL")
Expand All @@ -53,7 +53,7 @@ class CartRepository(

val data = storefrontApiClient.cartLinesAdd(cartId = cartId.id, lines = listOf(line))
val cart = data.cartLinesAdd?.cart
?: throw RuntimeException("Failed to add cart line")
?: throw CartOperationException("Failed to add cart line")

return cart.cartFragment.toLocal()
}
Expand All @@ -66,12 +66,12 @@ class CartRepository(
)
val data = storefrontApiClient.cartLinesUpdate(cartId = cartId.id, lines = listOf(line))
val cart = data.cartLinesUpdate?.cart
?: throw RuntimeException("Failed to modify cart")
?: throw CartOperationException("Failed to modify cart")
return cart.cartFragment.toLocal()
} else {
val data = storefrontApiClient.cartLinesRemove(cartId = cartId.id, lineIds = listOf(lineItemId.id))
val cart = data.cartLinesRemove?.cart
?: throw RuntimeException("Failed to modify cart")
?: throw CartOperationException("Failed to modify cart")
return cart.cartFragment.toLocal()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class StorefrontApiClient(
?.takeIf { errorMessages -> errorMessages.isNotBlank() }

if (storefrontErrors != null) {
throw RuntimeException("Storefront API error: $storefrontErrors")
throw StorefrontApiException("Storefront API error: $storefrontErrors")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.shopify.checkoutkit.androiddemo.common.client

class StorefrontApiException(message: String) : RuntimeException(message)
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ sealed class Screen(val route: String) {
Logs.route -> Logs
Login.route -> Login
Account.route -> Account
else -> throw RuntimeException("Unknown route")
else -> throw IllegalArgumentException("Unknown route: $route")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shopify.checkoutkit.androiddemo.products.collection.data

import com.shopify.checkoutkit.androiddemo.common.client.StorefrontApiClient
import com.shopify.checkoutkit.androiddemo.common.client.StorefrontApiException
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.last
import kotlinx.coroutines.flow.map
Expand Down Expand Up @@ -35,7 +36,7 @@ class ProductCollectionRepository(
return client.fetchCollection(handle = collectionHandle, numProducts = numberOfProducts)
.map { data ->
val collection = data.collection
?: throw RuntimeException("Failed to fetch collection")
?: throw StorefrontApiException("Failed to fetch collection")
collection.toLocal()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shopify.checkoutkit.androiddemo.products.product.data

import com.shopify.checkoutkit.androiddemo.common.client.StorefrontApiClient
import com.shopify.checkoutkit.androiddemo.common.client.StorefrontApiException
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.last
import kotlinx.coroutines.flow.map
Expand All @@ -17,7 +18,7 @@ class ProductRepository(
return client.fetchProduct(productId = productId, numVariants = 20)
.map { data ->
val product = data.product
?: throw RuntimeException("Failed to fetch product")
?: throw StorefrontApiException("Failed to fetch product")
val variants = product.variants.nodes.map { it.productVariantFragment.toLocal() }
product.productFragment.toLocal(variants)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exceptions:
TooGenericExceptionCaught:
active: false
TooGenericExceptionThrown:
active: false
active: true

naming:
FunctionNaming:
Expand Down
Loading