Skip to content

Commit

Permalink
fix(base): define errorHandler with private not use # (#3692)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe authored Nov 19, 2024
1 parent 163657a commit 40ad5ee
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/hono-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends string =
}

#notFoundHandler: NotFoundHandler = notFoundHandler
#errorHandler: ErrorHandler = errorHandler
// Cannot use `#` because it requires visibility at JavaScript runtime.
private errorHandler: ErrorHandler = errorHandler

/**
* `.route()` allows grouping other Hono instance in routes.
Expand Down Expand Up @@ -214,11 +215,11 @@ class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends string =
const subApp = this.basePath(path)
app.routes.map((r) => {
let handler
if (app.#errorHandler === errorHandler) {
if (app.errorHandler === errorHandler) {
handler = r.handler
} else {
handler = async (c: Context, next: Next) =>
(await compose<Context>([], app.#errorHandler)(c, () => r.handler(c, next))).res
(await compose<Context>([], app.errorHandler)(c, () => r.handler(c, next))).res
;(handler as any)[COMPOSED_HANDLER] = r.handler
}

Expand Down Expand Up @@ -263,7 +264,7 @@ class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends string =
* ```
*/
onError = (handler: ErrorHandler<E>): Hono<E, S, BasePath> => {
this.#errorHandler = handler
this.errorHandler = handler
return this
}

Expand Down Expand Up @@ -382,7 +383,7 @@ class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends string =

#handleError(err: unknown, c: Context<E>) {
if (err instanceof Error) {
return this.#errorHandler(err, c)
return this.errorHandler(err, c)
}
throw err
}
Expand Down Expand Up @@ -431,7 +432,7 @@ class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends string =
: res ?? this.#notFoundHandler(c)
}

const composed = compose<Context>(matchResult[0], this.#errorHandler, this.#notFoundHandler)
const composed = compose<Context>(matchResult[0], this.errorHandler, this.#notFoundHandler)

return (async () => {
try {
Expand Down

0 comments on commit 40ad5ee

Please sign in to comment.