waibu-rest-api 1.1.1 → 1.1.3
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.
- package/lib/error.js +4 -4
- package/package.json +1 -1
- package/plugin/factory.js +5 -3
package/lib/error.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { handler } from './not-found.js'
|
|
2
2
|
|
|
3
3
|
const extHandler = async function (err, req, reply, ctx) {
|
|
4
|
-
|
|
4
|
+
err.statusCode = err.statusCode ?? 500
|
|
5
5
|
const msg = err.message
|
|
6
|
-
if (msg === '_notFound') {
|
|
6
|
+
if (msg === '_notFound' || err.statusCode === 404) {
|
|
7
7
|
return handler.call(this, req, reply, ctx)
|
|
8
8
|
}
|
|
9
|
-
const data = ctx.httpErrors.createError(
|
|
10
|
-
data.statusCode =
|
|
9
|
+
const data = ctx.httpErrors.createError(err.statusCode, msg)
|
|
10
|
+
data.statusCode = err.statusCode
|
|
11
11
|
data.details = err.details
|
|
12
12
|
return this.transformResult({ data, req, reply })
|
|
13
13
|
}
|
package/package.json
CHANGED
package/plugin/factory.js
CHANGED
|
@@ -65,11 +65,13 @@ async function factory (pkgName) {
|
|
|
65
65
|
this.config.format.supported = uniq(this.config.format.supported)
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
routePath = (name) => {
|
|
69
|
-
const { get } = this.app.bajo.lib._
|
|
68
|
+
routePath = (name, { defFormat = '.json' } = {}) => {
|
|
69
|
+
const { get, trimStart } = this.app.bajo.lib._
|
|
70
70
|
const { fullPath, ns } = this.app.bajo.breakNsPath(name)
|
|
71
71
|
const prefix = get(this.app[ns], 'config.waibu.prefix', this.app[ns].alias)
|
|
72
|
-
|
|
72
|
+
const format = defFormat === false ? '' : (this.config.format.asExt ? defFormat : '')
|
|
73
|
+
const path = `/${this.config.waibu.prefix}/${prefix}${fullPath}${format}`
|
|
74
|
+
return '/' + trimStart(path, '/')
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
transformResult = ({ data, req, reply, options = {} }) => {
|