Feathersjs钩子错误总是返回500错误和html正文

时间:2018-02-21 23:07:08

标签: feathersjs

我正在使用before hook函数来验证一些查询参数。问题是,当我抛出一个新错误时,我总是收到一个500错误代码和一个HTML正文,如下所示,而不是400预期:

Response

我的钩子功能如下:

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');
    }
  }
}

1 个答案:

答案 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())

另见this FAQ entry