Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to check product was not found using stripe::Product::retrieve #464

Open
robiot opened this issue Dec 30, 2023 · 1 comment
Open

How to check product was not found using stripe::Product::retrieve #464

robiot opened this issue Dec 30, 2023 · 1 comment

Comments

@robiot
Copy link

robiot commented Dec 30, 2023

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

@augustoccesar
Copy link
Contributor

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"),
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants