feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
15.07k stars 752 forks source link

@feathersjs/errors and return throw new BadRequest #2885

Closed andysay closed 1 year ago

andysay commented 1 year ago
const { NotFound, GeneralError, BadRequest } = require("@feathersjs/errors");
module.exports = (options = {}) => {
    return async (context) => {
        const { app, data } = context;

        const result = app.service("users").find({
            query: {
                //both uniq
                $select: [data.email, data.username],
            },
        });

        const { total } = await result;

        if (total > 0) {
            throw new BadRequest("Invalid Parameters", {
                errors: {
                    //  how get whats really conflict in db?
                   ????  email? username? or both ... i want return to front for exactly status
                },
            });

        }
        return context;
    };
};

thx.