async-stripe
async-stripe copied to clipboard
How to check product was not found using stripe::Product::retrieve
Is your feature request related to a problem? Please describe.
No response
Describe the solution you'd like
let stripe_product = match stripe::Product::retrieve(
&state.stripe,
&stripe::ProductId::from_str(&product.id)?,
&[],
)
.await
{
Ok(stripe_product) => Some(stripe_product),
Err(error) => {
// what error type should be used here to know if it was found or not
}
};
I have searched through the docs, but I don't know what the error is named.
Describe alternatives you've considered
No response
Additional context
No response
Considering that this is the response from Stripe on this case:
{
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such product: 'prod_***'",
"param": "id",
"request_log_url": "https://dashboard.stripe.com/test/logs/req_***",
"type": "invalid_request_error"
}
}
Something like this probably works for you:
match Product::retrieve(
&state.stripe,
&stripe::ProductId::from_str(&product.id)?,
&[],
) {
Ok(_) => todo!("Handle found"),
Err(StripeError::Stripe(err)) if err.code == Some(ErrorCode::ResourceMissing) => {
todo!("Handle missing product");
}
Err(other_error) => todo!("Handle other errors"),
}