Skip to content

Commit b12d479

Browse files
committed
fix: fixed some issues
1 parent beb5bd3 commit b12d479

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

app.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class App<
5959
attach: (req: Req, res: Res, next: NextFunction) => void
6060

6161
// this symbol tells if a custom error handler has been set
62-
private readonly [hasSetCustomErrorHandler]: boolean
62+
[hasSetCustomErrorHandler]: boolean
6363

6464
constructor(options: AppConstructor<Req, Res> = {}) {
6565
super()
@@ -261,11 +261,9 @@ export class App<
261261
await applyHandler<Req, Res>(handler)(req, res, next)
262262
}
263263

264-
let idx = 0, err: unknown | undefined = null
264+
let idx = 0, err: unknown | undefined
265265
const next: NextFunction = async (error) => {
266-
if (error) {
267-
err = error
268-
}
266+
if (error) err = error
269267
return await loop()
270268
}
271269
const loop = async () =>
@@ -275,12 +273,12 @@ export class App<
275273

276274
await loop()
277275

278-
if (err instanceof Response) return err
276+
if (err instanceof Response) throw err
279277
else if (err) {
280-
if (this[hasSetCustomErrorHandler]) return await this.onError(err, req)
281-
else return err
278+
if (this[hasSetCustomErrorHandler]) throw await this.onError(err, req)
279+
else throw err
282280
}
283-
return new Response(res._body, res._init)
281+
throw new Response(res._body, res._init)
284282
}
285283

286284
handler = async (_req: Request, connInfo?: ConnInfo) => {
@@ -302,12 +300,14 @@ export class App<
302300
locals: {},
303301
}
304302

305-
306-
const k = await this.#prepare(req, res)
307-
308-
309-
if (k instanceof Response) return k
310-
return await this.onError(k, req)
303+
let err
304+
try {
305+
await this.#prepare(req, res)
306+
} catch (error) {
307+
err = error
308+
}
309+
if (err instanceof Response) return err
310+
return await this.onError(err, req)
311311
}
312312
/**
313313
* Creates HTTP server and dispatches middleware

url.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
const stripSlash = (path: string) => {
2-
const leadingSlash = path.charCodeAt(0) === 47
3-
const trailingSlash = path.charCodeAt(path.length - 1) === 47
4-
const start = leadingSlash ? 1 : 0
5-
path = path.slice(start)
6-
if (path.length && trailingSlash) path = path.slice(0, path.length - 1)
7-
return path
8-
}
9-
101
/**
112
* This function joins a list of paths with / (forward slash)
123
* @param {boolean} padLeft - pads the final path with leading slash if it does not exist
@@ -33,4 +24,4 @@ const pathJoin = (padLeft: boolean, padRight: boolean, ...path: string[]) => {
3324
return finalString
3425
}
3526

36-
export { pathJoin, stripSlash }
27+
export { pathJoin }

0 commit comments

Comments
 (0)