-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Open
Labels
Description
Description: The JSDoc for HttpError in Koa states:
A re-export of HttpError from the http-error package. This is the error type that is thrown by ctx.assert() and ctx.throw().
However, ctx.assert() actually throws specific error class, not the HttpError class. This breaks instanceof HttpError checks in error handling.
Code to reproduce
import { HttpError } from 'koa'
const router = new Router()
router.get('/test', async (ctx) => {
try {
const data = null
ctx.assert(data, 401, 'Unauthorized')
} catch (e) {
console.log(e instanceof HttpError) // ❌ false - should be true
}
})
Reactions are currently unavailable