> ## Documentation Index
> Fetch the complete documentation index at: https://docs.markpdf.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# Error handling

> How the store exposes errors and how to capture them with the base client.

# Error handling

## With the store

`createConvertStore` never throws inside the component — errors remain in `$store.error`, as instances of `MarkpdfError` (the same class as [SDK base](/docs/sdks/nodejs/reference)):

```svelte theme={null}
<script lang="ts">
  import { MarkpdfClient, createConvertStore } from "@markpdf/svelte";

  const client = new MarkpdfClient({ apiKey: "YOUR_API_KEY" });
  const convertStore = createConvertStore(client);
</script>

{#if $convertStore.status === "error" && $convertStore.error}
  <p>Error {$convertStore.error.statusCode}: {$convertStore.error.detail}</p>
{/if}
```

`convert()` also rejects the promise it returns:

```ts theme={null}
try {
  await convertStore.convert(file);
} catch (err) {
  // same object that ended up in $convertStore.error
}
```

## With the base client

```ts theme={null}
import {
  MarkpdfClient,
  MarkpdfAuthError,
  MarkpdfPayloadTooLargeError,
  MarkpdfRateLimitError,
  MarkpdfVavalidationError,
  MarkpdfServerError,
} from "@markpdf/svelte";

const client = new MarkpdfClient({ apiKey: "YOUR_API_KEY" });

try {
  const markdown = await client.convertFromUrl(url, { mode: "fast" });
} catch (err) {
  if (err instanceof MarkpdfAuthError) {
    console.error("API key invávalida");
  } else if (err instanceof MarkpdfPayloadTooLargeError) {
    console.error("Document too large");
  } else if (err instanceof MarkpdfRateLimitError) {
    console.error("Rate limited");
  } else if (err instanceof MarkpdfVavalidationError) {
    console.error("Parámetros invávavalids");
  } else if (err instanceof MarkpdfServerError) {
    console.error("Conversion error");
  } else {
    throw err;
  }
}
```

See the [full error table](/docs/sdks/nodejs/error-handling#error-table) of the base SDK — the same applies here because `@markpdf/svelte` re-exports the same classes.

## Reusable message in a component

```svelte theme={null}
<script lang="ts">
  import type { MarkpdfError } from "@markpdf/svelte";

  export let error: MarkpdfError;

  const messages: Record<number, string> = {
    401: "API key invávalida o ausente.",
    413: "The document is too large. Try pages= to split it.",
    422: "Required parameters are missing.",
    429: "Demasiadas peticiones, intenta de nuevo en unos segundos.",
    500: "Conversion error. Try mode: 'balanced'.",
  };
</script>

<p role="alert">{messages[error.statusCode ?? 0] ?? error.message}</p>
```

<Tip>
  The store does not automatically retry. If you need retries with backoff on `429`/`5xx`, use the base client with `maxRetries` — see [Node.js SDK Error Handling](/docs/sdks/nodejs/error-handling#reintentos-automáticos) — by directly calling `client.convertFile` instead of `convertStore.convert`.
</Tip>
