Skip to content

@feathersjs/errors and return throw new BadRequest #2898

Answered by daffl
andysay asked this question in Q&A
Discussion options

You must be logged in to vote

I don't think the queries you are making will do what you expect. If you want to differentiate the error message between if email and username already exists, this should work:

const { NotFound, GeneralError, BadRequest } = require("@feathersjs/errors");

module.exports = (options = {}) => {
    return async (context) => {
        const { app, data } = context;

        const { total: emailTotal } = app.service("users").find({
            query: {
                email: data.email,
                $limit: 0
            },
        });
        const { total: usernameTotal } = app.service("users").find({
            query: {
                username: data.username,
                $limit: 0

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@andysay
Comment options

Answer selected by andysay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2885 on November 27, 2022 21:43.