TypeScript 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 handler does not run. The route stays closed until a payment has settled.
Your code only sees an error 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 handler does not run. When the payment has settled, your handler runs with the payment available to it. When the price for a request is null, 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.
Error classes
Every error the package throws is an instance of MituError. Error messages never contain your key, a payment credential or any request data, so they are safe to log.
MituApiError has two extra properties. The status property holds the HTTP status Mitu returned, or 0 if no response arrived at all. The retryable property is true for network failures, rate limiting and server errors. The SDK already turns those temporary failures into the 503 response described above, so the MituApiError instances that reach your code are the ones a retry will not fix.
Handling errors
A MituConfigError means something is wrong with how the SDK has been set up. Treat it as a deployment problem and let your server 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. Catch it in your framework’s error handler, log it, and alert whoever looks after your Mitu account. The example below shows one way to do this in Express.
When your handler fails after payment
Once a payment has settled it is final. If your handler 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.