SolidJSS
SolidJSโ€ข3y agoโ€ข
3 replies
danboyle8637

Catching Errors from async requests started in onMount

There must be a hole in my Solid knowledge. I want to run a fetch request on component mount. This is not fetching any data so I don't want to use createResource

This async request is taking state and saving it to the database.

However, how do I catch any errors. When the async function throws... the error is always uncaught.

Example code:

import { getTestEndpoint } from "../../utils/networkFunctions";

export const TestError = () => {
  onMount(() => {
    const runAsync = async () => {
      await getTestEndpoint();
    };

    runAsync();
  });

  return <h1>Test Error</h1>;
};


The test endpoint purposely returns a 500 status code which then throws an error.

But I can't catch this error with an ErrorBoundary... can't catch it with try/catch

What am I missing?
Was this page helpful?