feat: browser router add custom error

This commit is contained in:
2024-11-01 00:23:21 +08:00
parent d6eb8393e0
commit c462dc31f8
6 changed files with 58 additions and 54 deletions

View File

@@ -1,4 +1,4 @@
import { QueryRouterServer } from '@kevisual/router';
import { CustomError, QueryRouterServer } from '@kevisual/router/browser';
const router = new QueryRouterServer();
@@ -12,6 +12,18 @@ router
})
.addTo(router);
router
.route({
path: 'hello',
key: 'world2',
})
.define(async (ctx) => {
ctx.body = 'Hello, world!';
// throw new CustomError('error');
throw new CustomError(5000, 'error');
})
.addTo(router);
router
.run({
path: 'hello',
@@ -20,3 +32,12 @@ router
.then((res) => {
console.log(res);
});
router
.run({
path: 'hello',
key: 'world2',
})
.then((res) => {
console.log(res);
});