0

I've created a Register/Login form, and while it works perfectly for both, it's the error messages that are stumping me.

I've tried to produce the following errors for registering:

  1. email already in use
  2. username already in use
  3. missing field

But no matter what I do the error I get is always "Request failed with status code 400"

This is the code I'm using to make the post request to create a user:

    const { username, password, email } = this.state;
    axios
      .post(`${Config.apiUrl}/wp/v2/users/register`, {
        username: username,
        password: password,
        email: email,
      })
      .catch(err => {
        console.log(err)
      });

How do I get wordpress to spit out a more specific error?

0

The problem I was having is that I wasn't receiving the full error object. To do that I changed the code to:

    const { username, password, email } = this.state;
    axios
      .post(`${Config.apiUrl}/wp/v2/users/register`, {
        username: username,
        password: password,
        email: email,
      })
      .catch(err => {
        console.log({err})
      });

Which then allowed me to figure out that the error message is contained in: err.response.data.message

So now I'm all good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.