|
|
@@ -22,8 +22,6 @@ module.exports = function(crowi, app) {
|
|
|
const i18nUserSettingDetector = require('../util/i18nUserSettingDetector');
|
|
|
const env = crowi.node_env;
|
|
|
const middleware = require('../util/middlewares');
|
|
|
- const toArrayIfNot = require('../../lib/util/toArrayIfNot');
|
|
|
- const ErrorV3 = require('../util/ErrorV3');
|
|
|
|
|
|
// Old type config API
|
|
|
const config = crowi.getConfig();
|
|
|
@@ -152,34 +150,4 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
|
|
|
app.use(i18nMiddleware.handle(i18next));
|
|
|
-
|
|
|
- // add custom functions to express res
|
|
|
- express.response.apiv3 = function(obj) { // not arrow function
|
|
|
- // obj must be object
|
|
|
- if (typeof obj !== 'object' || obj instanceof Array) {
|
|
|
- throw new Error('invalid value supplied to res.apiv3');
|
|
|
- }
|
|
|
-
|
|
|
- this.json({ data: obj });
|
|
|
- };
|
|
|
-
|
|
|
- express.response.apiv3Err = function(_err, status = 400) { // not arrow function
|
|
|
- if (!Number.isInteger(status)) {
|
|
|
- throw new Error('invalid status supplied to res.apiv3Err');
|
|
|
- }
|
|
|
-
|
|
|
- let errors = toArrayIfNot(_err);
|
|
|
- errors = errors.map((e) => {
|
|
|
- if (e instanceof ErrorV3) {
|
|
|
- return e;
|
|
|
- }
|
|
|
- if (typeof e === 'string') {
|
|
|
- return { message: e };
|
|
|
- }
|
|
|
-
|
|
|
- throw new Error('invalid error supplied to res.apiv3Err');
|
|
|
- });
|
|
|
-
|
|
|
- this.status(status).json({ errors });
|
|
|
- };
|
|
|
};
|