Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle errors thrown from the loader? #356

Closed
lilouartz opened this issue Jun 27, 2024 · 5 comments · Fixed by #357
Closed

How to handle errors thrown from the loader? #356

lilouartz opened this issue Jun 27, 2024 · 5 comments · Fixed by #357

Comments

@lilouartz
Copy link

At the moment, this code:

import { defineLoader } from '#app/unstable';

export const loader = defineLoader(async () => {
  throw new Error('This is an error');
});

Produces this page:

https://pillser.com/checks/error

In Fastify, this is how I am handling it:

try {
  const handler = createRequestHandler({
    build: serverBuild,
    getLoadContext() {
      return {
        nonce: cspNonce,
        session: request.session as unknown as Session,
      };
    },
    mode: 'production',
  });

  return handler(request, reply);
} catch (error) {
  return reply.status(500).send('Internal Server Error');
}

How do I get Remix error page instead?

@lilouartz
Copy link
Author

Also, while testing, I noticed that if I create route such as:

export default async () => {
  throw new Error('This is an error');
};

The error becomes:

Error: `line` must be greater than 0 (lines start at line 1)

This feels like a separate issue.

@mcansh
Copy link
Owner

mcansh commented Jun 28, 2024

This feels like a separate issue.

I'll leave them together for now, and i'll open a new issue if it's not resolved by any changes from this one :)

@lilouartz
Copy link
Author

@mcansh Any updates on this one?

@mcansh
Copy link
Owner

mcansh commented Jul 3, 2024

hey sorry for the slowness, been busy with work. from what i can tell this is due to streaming with a pass through stream https://github.com/mcansh/remix-fastify/blob/main/packages/remix-fastify/src/server.ts#L134 - i'll investigate further soon

removing the pass through doesn't work in all instances

@mcansh mcansh linked a pull request Jul 31, 2024 that will close this issue
@mcansh
Copy link
Owner

mcansh commented Aug 1, 2024

i have an experimental release for you to try if you're still using this package :)

npm i @mcansh/remix-fastify@experimental or npm i @mcansh/remix-fastify@0.0.0-experimental-507702b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants