Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If an error occurs when creating a user, a more kind error message is necessary #290

Open
suzuki opened this issue May 21, 2018 · 1 comment

Comments

@suzuki
Copy link
Member

suzuki commented May 21, 2018

About

  • If an error occurs when creating a user, a more kind error message is necessary

Reproduce

  • Login as admin
  • Move Admin -> ユーザー管理 menu
  • Create a new user with the same email address as an existing user
    • In this time, I used aoi@example.com

screenshot 2018-05-21 17 21 55

- The error has come with `作成失敗` message

screenshot 2018-05-21 17 22 07

- But, I don't know why the error occured
@dyong0
Copy link

dyong0 commented Jun 29, 2018

Investigation

The error message is written in the view.

<pre>{% for cUser in createdUser %}{% if cUser.user %}{{ cUser.email }} {{ cUser.password }}<br>{% else %}{{ cUser.email }} 作成失敗<br>{% endif %}{% endfor %}</pre>

And it's displayed only if cUser.user is empty. And the view variable createdUser, which is the parent of cUser, is from the flash of the view, which again originates from action user.invite.

The action sets createdUser based on the result of a User model creation using User.createUsersByInvitation. There are 2 spots that makes an element of createdUser empty in the function.

When there's a user already existing:

User.findOne({ email: email }, function(err, userData) {
  // The user is exists
  if (userData) {
    createdUserList.push({
      email: email,
      password: null,
      user: null,
    })

When failed to save a new user:

newUser.save(function(err, userData) {
  if (err) {
    createdUserList.push({
      email: email,
      password: null,
      user: null,
    })
    debug('save failed!! ', email)

This eventually causes false-failure; failed to create a new user but succeeded the model creation(User.createUsersByInvitation). Currently, always null error is given:

return callback(null, createdUserList)

Solutions

It will be nice to pass an error to the caller in User.createUsersByInvitation instead of giving an invalid result. Then print the error message using the flash.

Maybe you can use a promise instead of async.each as other functions do in User model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants