Reputation: 13
I am using a before hook function to validate some query parameters. The problem is that when I throw a new error I always receive a 500 error code and an HTML body as follows, not a 400 as expected:
My hook function is the following:
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');
}
}
}
Upvotes: 1
Views: 382
Reputation: 44215
Just like Express, you have to add your own error handler. You can use the errorHandler()
that comes with the @feathersjs/express
module as documented here:
const feathers = require('@feathersjs/feathers');
const express = require('@feathersjs/express');
const app = express(feathers());
// before starting the app
app.use(express.errorHandler())
Also see this FAQ entry.
Upvotes: 2