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

Axios 500 Error Problem #6319

Open
Gam5g opened this issue Mar 25, 2024 · 3 comments
Open

Axios 500 Error Problem #6319

Gam5g opened this issue Mar 25, 2024 · 3 comments

Comments

@Gam5g
Copy link

Gam5g commented Mar 25, 2024

Describe the issue

I've tried running the code provided to create a user registration feature, but I'm facing a 500 Axios Error. I've confirmed through Postman and Swagger that data is received correctly. I don't see any issues in the backend code. Could there be any problems with the code above?

I'm receiving the user ID, password, and email via input tags and using them with useForm like {...register("id")}. I've also debugged it by logging each value, such as console.log(id), and everything seems to be receiving the data correctly.

I've been stuck on this for days and it's frustrating.

Example Code

const onSubmit = (formData) => {
    axios
      .post(
        "http://example.com/api/auth/sign-up",
        {
          id: formData.id,
          password: formData.password,
          email: formData.email,
        },
        {
          headers: {
            "Content-Type": "application/json",
          },
        }
      )
      .then((response) => {
        if (response.status !== 200) {
          throw new Error("Network response was not ok");
        }
        return response.data;
      })
      .then((result) => {
        console.log("result :", result);
        navigate("../login");
      })
      .catch((error) => console.error("error:", error));
  };

Expected behavior

No response

Axios Version

1.6.7

Adapter Version

HTTP

Browser

Chrome

Browser Version

No response

Node.js Version

No response

OS

No response

Additional Library Versions

React 18.2.0
axios : ^1.6.7
swagger-ui:5.12.0

Additional context/Screenshots

No response

@Gam5g
Copy link
Author

Gam5g commented Mar 25, 2024

did.
const onSubmit = () => {
const formData = {
id = watch("id"),
password = watch("password")
}
axios
.post(
"http://example.com/api/auth/sign-up",
{
id: formData.id,
password: formData.password,
email: formData.email,
},

@justindhillon
Copy link

If you have the back end code snippet, I can better diagnose the problem.

@Gam5g
Copy link
Author

Gam5g commented Mar 27, 2024

Thank you for answering my message :)
I was making a membership with useForm and not useState, but this is a problem caused by forgetting the existence of a function called watch for a while. The problem seems to have been purely my problem, not the backend problem.

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