Error Handling
Occasionally, operations might fail to be submitted or injected. Kukai-embed returns a custom error payload that includes both a low-level errorId that you can map to friendlier messages, as well as an errorMessage that describes the nature of the error.
tip
Kukai-embed runs simulations before presenting confirmation modals. If an operation fails during a simulation, it is likely that the low-level RPC errorId will not exist, as the error may be related to something else.
Error example
{
error: "INVALID PARAMETERS",
errorId: "proto.020-PsParisC. implicit.empty_implicit_contract",
errorMessage: "No manager operations are allowed on an empty implicit contract"
type: "operation response"
}
Errors may be thrown when using login, send, authenticate, and signExpr.
When catching an error, you may inspect the errorId and present a custom message:
try {
const operationHash = await kukaiEmbed.send(payload);
} catch (error) {
// update the UI
const customMessage = getErrorMessage(error.errorId); // optionally use a different message if a low-level RPC errorId exists
throw new Error(customMessage || error.errorMessage);
}