Skip to main content

Error Handling

Restate handles retries for failed invocations. By default, Restate does infinite retries with an exponential backoff strategy.

For failures for which you do not want retries, but instead want the invocation to end and the error message to be propagated back to the caller, you can throw a terminal error.

You can throw a terminal error with an optional HTTP status code and a message anywhere in your handler, as follows:

throw new TerminalError("Something went wrong.", { errorCode: 500 });

You can catch terminal exceptions. For example, you can catch the terminal exception that comes out of a call to another service, and build your control flow around it.

Sagas with Restate

When you throw a terminal error, you might need to undo the actions you did earlier in your handler to make sure that your system remains in a consistent state. Have a look at our Sagas guide to learn more.