waibu-rest-api 2.3.1 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,8 +2,8 @@ import path from 'path'
2
2
  import decorate from '../../lib/decorate.js'
3
3
  import routeByModelBuilder from '../../lib/route-by-model-builder.js'
4
4
  import routeByVerb from '../../lib/route-by-verb.js'
5
- // import notFound from '../../lib/not-found.js'
6
- // import error from '../../lib/error.js'
5
+ import notFoundHandler from '../../lib/not-found.js'
6
+ import errorHandler from '../../lib/error.js'
7
7
  import subApp from '../../lib/sub-app.js'
8
8
  import handleResponse from '../../lib/handle-response.js'
9
9
 
@@ -15,6 +15,8 @@ function formatExt (item) {
15
15
 
16
16
  const boot = {
17
17
  level: 10,
18
+ notFoundHandler,
19
+ errorHandler,
18
20
  handler: async function (prefix) {
19
21
  const { importPkg, eachPlugins, importModule, runHook } = this.app.bajo
20
22
  const { fastGlob } = this.app.lib
@@ -44,7 +46,6 @@ const boot = {
44
46
  await handleMultipart.call(this, this.config.multipart)
45
47
  await handleCompress.call(this, this.config.compress)
46
48
  await handleResponse.call(this)
47
- // await error.call(this)
48
49
  await runHook(`${this.ns}:beforeCreateRoutes`, this.webAppCtx)
49
50
  const actions = ['find', 'get', 'create', 'update', 'remove']
50
51
  if (this.config.enablePatch) actions.push('replace')
@@ -86,7 +87,6 @@ const boot = {
86
87
  })
87
88
  await runHook(`${this.ns}:afterCreateRoutes`, this.webAppCtx)
88
89
  await subApp.call(this)
89
- // await notFound.call(this)
90
90
  }
91
91
  }
92
92
 
package/lib/error.js CHANGED
@@ -12,10 +12,8 @@ const extHandler = async function (err, req, reply) {
12
12
  return this.transformResult({ data, req, reply })
13
13
  }
14
14
 
15
- async function error () {
16
- const { importModule } = this.app.bajo
17
- const errorHandler = await importModule('waibu:/lib/webapp-scope/error-handler.js')
18
- await errorHandler.call(this, extHandler)
15
+ async function error (err, req, reply) {
16
+ return await extHandler.call(this, err, req, reply)
19
17
  }
20
18
 
21
19
  export default error
package/lib/not-found.js CHANGED
@@ -4,11 +4,8 @@ export function handler (req, reply) {
4
4
  return this.transformResult({ data, req, reply })
5
5
  }
6
6
 
7
- async function notFound () {
8
- const me = this
9
- await this.webAppCtx.setNotFoundHandler(async function (req, reply) {
10
- return handler.call(me, req, reply)
11
- })
7
+ async function notFound (err = {}, req, reply) {
8
+ return handler.call(this, req, reply)
12
9
  }
13
10
 
14
11
  export default notFound
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-rest-api",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "description": "REST API for Waibu",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-02-09
4
+
5
+ - [2.4.0] Add error & not found handlers
6
+
3
7
  ## 2026-02-08
4
8
 
5
9
  - [2.3.0] Simplify webApp context through ```plugin.webAppCtx```