Skip to content

Commit

Permalink
add dev error page
Browse files Browse the repository at this point in the history
  • Loading branch information
lixinyang123 committed May 24, 2024
1 parent c5776d9 commit 25a0c8b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/middleware/errorpage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default async function(req, res, next) {
await next(req, res).catch(error => {
res.error(JSON.stringify({ error }))
})
}
12 changes: 12 additions & 0 deletions lib/plankton.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Cors from './middleware/cors.js'
import StaticFile from './middleware/staticfile.js'
import PathBase from './middleware/pathbase.js'
import Session from './middleware/session.js'
import ErrorPage from './middleware/errorpage.js'

export class Plankton {
constructor() {
Expand Down Expand Up @@ -147,6 +148,17 @@ export class Plankton {
return this.use(StaticFile(wwwroot, requestPath))
}

/**
* Use developer error page to show error info
* @returns {Plankton} Plankton app
*
* @example
* app.useDevErrorPage()
*/
useDevErrorPage() {
return this.use(ErrorPage)
}

/**
* Map endpoint
* @param {string} routePath endpoint path
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lixinyang123/plankton",
"version": "0.2.5",
"version": "0.2.6",
"description": "Fast, Sample, Zero dependenecs Node.js mvc web framework",
"author": "lllxy",
"type": "module",
Expand Down

0 comments on commit 25a0c8b

Please sign in to comment.