I’m using the following script for creating a user with the Custom DB feature (modified to remove URL). I am returning the correct error messages to the callback() function callback('Email ' + body.errors.email); but my users are only seeing
WE’RE SORRY, SOMETHING WENT WRONG WHEN ATTEMPTING TO SIGN UP.
Is there any way I can show them the error messages? For example if email is taken, or password doesn’t match our policy.
function create (user, callback) {
console.log(user);
request.post({
url: 'BASE_URL/users.json',
json: true,
body: {
user: {
email: user.email,
password: user.password,
password_confirmation: user.password
}
}
//for more options check:
//https://github.com/mikeal/request#requestoptions-callback
}, function (err, response, body) {
console.log("err", err);
console.log("body", body);
console.log("response.statusCode", response.statusCode);
if (err) return callback(err);
if (response.statusCode === 401) return callback();
if (response.statusCode === 422 && body.errors) {
if (body.errors.email) {
callback('Email ' + body.errors.email);
} else if (body.errors.password) {
callback('Password ' + body.errors.password);
}
}
if (response.statusCode !== 201) return callback();
console.log(body);
callback(null, {
user_id: body.id,
email: body.email,
nickname: body.email
});
});
}