我正在使用before hook函数来验证一些查询参数。问题是,当我抛出一个新错误时,我总是收到一个500错误代码和一个HTML正文,如下所示,而不是400预期:
我的钩子功能如下:
const errors = require('@feathersjs/errors');
function validateFindQueryParameters(options){
return context => {
const c = {...context};
const q = c.params.query;
if(!q.hasOwnProperty("ticketStatus") || q.ticketStatus === ""){
throw new errors.BadRequest('ticketStatus is not present or empty');
}
}
}
答案 0 :(得分:0)
就像Express一样,你必须添加自己的错误处理程序。您可以将errorHandler()
模块随附的@feathersjs/express
用作documented here:
const feathers = require('@feathersjs/feathers');
const express = require('@feathersjs/express');
const app = express(feathers());
// before starting the app
app.use(express.errorHandler())