Python SDK errors
Most things that can go wrong with a payment never reach your code. If a caller has not paid, has paid for the wrong route or has had a payment refused, the SDK replies to the caller directly and your view does not run. The route stays closed until a payment has settled.
Your code only sees an exception in two situations. The first is a problem with your setup, such as an invalid key or price. The second is Mitu rejecting a call from the SDK itself, which usually means your key needs attention. This page covers both.
Responses the SDK sends for you
The table below shows how the SDK answers each kind of request. In every case except the last two, your view does not run. When the payment has settled, your view runs with the payment available to it. When the price for a request is None, it runs without one.
An outage at Mitu never causes a route to be served unpaid. The caller is told to try again later instead.
Exception classes
Every exception the package raises is a subclass of MituError. Exception messages never contain your key or a payment credential, so they are safe to log.
Rate limiting and server errors at Mitu are temporary, so the SDK does not raise them. It answers the caller with the 503 response described above instead.
Handling exceptions
A MituConfigError means something is wrong with how the SDK has been set up. Treat it as a deployment problem and let your application fail to start, so that the mistake is caught before any traffic arrives.
A MituApiError that reaches your code usually means the key has been revoked or is no longer valid. Handle it in your framework’s error handling, log it, and alert whoever looks after your Mitu account. The example below shows one way to do this in FastAPI.
When your view fails after payment
Once a payment has settled it is final. If your view fails after the caller has paid, do not ask the caller to pay again. Retry the work, or refund the payment, so that the caller is never charged twice for one result.