AxiosError code: "ERR_BAD_RESPONSE" config: {transitional: {…}

Viewed 655

I am trying to add user using redux but getting an axios error code "ERR_BAD_RESPONSE"

this is my add user redux code.

  addUserStart: (state) => {
                state.isFetching = true;
                state.error = false;
            },
            addUserSuccess: (state, action) => {
                state.isFetching = false;
                state.users.push(action.payload);
            },
            addUserFailure: (state) => {
                state.isFetching = false;
                state.error = true;
            },

and this is the api request.

export const addUser = async (user, dispatch) => {
    dispatch(addUserStart());
    try {
        const res = await publicRequest.post("/auth/register", user);
        dispatch(addUserSuccess(res.data))
    } catch (err) {
        console.log(err)
        dispatch(addUserFailure());
    }
};

This is my handle click function.

   const handleClick = (e) => {
    e.preventDefault();
    const fileName = new Date().getTime() + file.name
    const storage = getStorage(app);
    const StorageRef = ref(storage, fileName)
    const uploadTask = uploadBytesResumable(StorageRef, file);

    // Register three observers:
    // 1. 'state_changed' observer, called any time the state changes
    // 2. Error observer, called on failure
    // 3. Completion observer, called on successful completion
    uploadTask.on('state_changed',
      (snapshot) => {
        // Observe state change events such as progress, pause, and resume
        // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
        const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
        console.log('Upload is ' + progress + '% done');
        switch (snapshot.state) {
          case 'paused':
            console.log('Upload is paused');
            break;
          case 'running':
            console.log('Upload is running');
            break;
        }
      },
      (error) => {
        // Handle unsuccessful uploads
      },
      () => {
        getDownloadURL(uploadTask.snapshot.ref).then((downloadURL) => {
          const user = { ...inputData, img: downloadURL };
         await addUser(user, dispatch);
        });
      }
    );
  }

after all this i am getting this error.

AxiosError
code: "ERR_BAD_RESPONSE"
config: {transitional: {…}, transformRequest: Array(1), transformResponse: Array(1), timeout: 0, adapter: ƒ, …}
message: "Request failed with status code 500"
name: "AxiosError"
request: XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}
response: {data: {…}, status: 500, statusText: 'Internal Server Error', headers: {…}, config: {…}, …}
[[Prototype]]: Error

i am not sure why i am getting this error. if anyone know please tell me.

0 Answers
Related