Skip to content

Not possible to configure onError #163

@luchsamapparat

Description

@luchsamapparat

Hi,

I noticed that my custom error logging wasn't working for errors thrown from within the React Router app. From what I can see it is currently not possible to use onError properly.

createHonoServer initializes a new Hono instance (see here):

  const reactRouterApp = new Hono<E>({
    strict: false,
  });

Since no error handler is configured, this instance has Hono's default error handler (see here).

The reactRouterApp is then configured as route handler:

 app.route(`${basename}`, reactRouterApp);

app.route(...) checks if the reactRouterApp's errorHandler is the default error handler (which it is) and then adopts that (see here):

    app.routes.map((r) => {
      let handler
      if (app.errorHandler === errorHandler) { // 👈 here
        handler = r.handler
      } else {
        handler = async (c: Context, next: Next) =>
          (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res
        ;(handler as any)[COMPOSED_HANDLER] = r.handler
      }

      subApp.#addRoute(r.method, r.path, handler)
    })

Can you provide a way to configure onError for the reactRouterApp as well? Maybe just adopt the errorHandler from the app that can be passed into createHonoServer? That's at least how I expected it to work.

Apart from that, thanks for the great work with this library!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions