> For the complete documentation index, see [llms.txt](https://docs.dedot.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dedot.dev/client-api/errors.md).

# Errors

Pallet errors are thrown out when things go wrong in the runtime, those are defined in the metadata. Available errors for each pallet are also exposed in `ChainApi` interface, so we can get information an error through this syntax: `client.errors.<pallet>.<errorName>`. E.g: Available errors for Polkadot network can be found [here](https://github.com/dedotdev/chaintypes/blob/main/packages/chaintypes/src/polkadot/errors.d.ts).

Similar to Event API, this API is helpful when we want to check if an error maches with an error that we're expecting.

Example to check if an error is `AlreadyExists` from `Assets` pallet:

```typescript
// From system events
await client.query.system.events(async (records) => {
  for (const tx of records) {
    if (client.events.system.ExtrinsicFailed.is(tx.event)) {
      const { dispatchError } = tx.event.palletEvent.data;
      if (client.errors.assets.AlreadyExists.is(dispatchError)) {
        console.log('Assets.AlreadyExists error occurred!');
      } else {
        console.log('Other error occurred', dispatchError);
      }
    }
  }
});
```

Example checking for error details in transaction callback:

```typescript
// Or from events in transaction callback
client.tx.balances.transferKeepAlive('<BOB_ADDRESS>', 1_000n)
  .signAndSend(aliceAddressOrKeyPair, ({ dispatchError, events }) => {
    if (dispatchError) { // DispatchError extracted from ExtrinsicFailed event if any
      // Check for specific error
      if (client.errors.balances.InsufficientBalance.is(dispatchError)) {
        console.log('Balance too low to send value!');
      } else {
        console.log('Other error occurred', dispatchError);
      }
      
      // Check by finding error metadata
      const errorMeta = client.registry.findErrorMeta(dispatchError);
      if (errorMeta) {
        const { pallet, name, docs } = errorMeta;
        console.log(`Error: [${pallet}][${name}] - ${docs.join(',')}`);
      }
    }
  });
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.dedot.dev/client-api/errors.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
