I want to response an error message when email already exists. I used reject(message)
in resolve function, and I got an error message what I want in graphiql. But my console always shows an error, I hope the console doesn't show error. How can do?
resolve:
return new Promise(async (resolve, reject) => {
let results = await User.find({ email });
if (results.length > 0) {
reject('用户已存在(。ì _ í。)');
} else {
let user = new User({
email,
password: await b.hash(password, 10),
date: Date.now()
});
resolve(user.save());
}
});
index:
app.use('/graphql', bodyParser.json(), graphqlExpress({
schema,
context: {
db
},
formatError: error => {
return error;
}
})
);
我设置了export NODE_ENV=production
,该错误已解决。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.