Skip to navigation

Errors and recovery

How the Mitu API reports errors, what each one means and how to recover without losing or repeating work.
View as Markdown

Every integration encounters errors, from a missing field to a network connection that drops at the wrong moment. What matters is recovering from them safely, without charging a customer twice, losing a payment or leaving your records out of step with Mitu. This page explains how errors are reported and the practices that keep recovery reliable.

How errors are reported

The Mitu API reports each error with a standard HTTP status and a JSON body that explains what went wrong.

{
"statusCode": 400,
"message": "Send exactly one of recipientId or recipient",
"error": "Bad Request"
}

When a request fails validation on several fields, message is a list with one entry for each problem.

StatusMeaningRecommended action
400The request is invalid.Correct the request using the message. Do not retry it unchanged.
401The API key is missing or invalid.Check the key and the environment it belongs to.
404The resource does not exist.Check the identifier and the environment in which it was created.
409The request conflicts with the current state, such as cancelling a paid invoice or reusing an idempotency key with a different body.Retrieve the resource to see its current state.
410The resource is no longer available, such as a cancelled invoice.Create a new one if it is still needed.
429Too many requests.Wait, then retry with increasing delays.
5xxA temporary problem on the Mitu side.Retry with increasing delays, using the same idempotency key.

Recovering safely

1

Retry creations with an idempotency key

When a request that creates something times out, you cannot tell whether it succeeded. Send an Idempotency-Key header with every request that creates a resource, and retry with the same key, so a retry returns the original result instead of creating a second payment link or invoice.

2

Never charge twice for undelivered work

A payment can complete even if your API then fails to perform the work. Treat payment and fulfilment as separate states, and if fulfilment fails after payment, complete the work later or refund the payer, but never ask them to pay again.

3

Rely on events, not on redirects

A browser can close and an agent can lose its connection after paying. Determine that a payment is complete from the notification sent through events, or by retrieving the resource through the API, never from what the payer’s browser or agent reports.

4

Recover missed events

If your endpoint was unavailable, Mitu continues to retry each event, and any event that was still missed can be resent from Logs. Delivery and retries describes the schedule.

Error handling practices

  1. Log the full error response
    Record the status and message of every error, so failures can be diagnosed without reproducing them.
  2. Distinguish errors you can retry
    Retry only temporary failures, such as a 429 or a 5xx status, and correct the request for every other error.
  3. Alert on patterns, not single failures
    Monitor the rate of errors over time, so that a genuine problem is noticed quickly without alerting on every isolated failure.

Handled in this way, errors become routine events your integration absorbs, rather than incidents that disrupt your customers or your records.