AjobK / Seaqull

Seaqull programming blog
http://www.seaqull.com
3 stars 0 forks source link

[408] Refactor formInpur, RegistorPrompt and LoginPrompt #408

Open AjobK opened 2 years ago

AjobK commented 2 years ago

Bug display and/or description The current implementation of error handling is very poor. It is sensitive to changes in language and unnecessarily complex. For example, see code below:

handleError = (msg) => {
    const errors = {
      username: [],
      email: [],
      password: [],
      generalError: [],
    }

    for (const elem of msg) {
      const error = elem.toLowerCase()

      errors[error.split(' ')[0]].push(error)

      errors.generalError.push(elem)
    }

    this.setState({
      username: errors.username,
      email: errors.email,
      password: errors.password,
      generalError: errors.generalError,
    })
  }

This procedure checks the first word for each error in an array. With this first word (in lowercase) it assigns the whole error string to a dictionary key. The problem with this is that it is language and content dependent. Instead, send a better format for this from the back-end or find a fitting front-end solution.

Reproduce

Branch

-hotfix-