0

I'm having the following issue when I try to delete a register by axios:

Cannot use 'in' operator to search for 'validateStatus' in {"name_group":"BBBB","UMB":"BS"}

This is my code to delete the register:

    export const deleteProduct= async (product) => {
        const params = JSON.stringify({
        "name_group":product.name_group,
        "UMB": product.UMB
        });
    
        return await axios.delete("https://anyDomanin.cloud/Inventory/products/", params,{
            "headers": {
              "content-type": "application/json",
            },
          });
    };

The create, update and get functions work perfectly, but when I delete appears this issue.

Current version of axios: 0.20.0

PD: When I do it by postman delete works, but when I do it by my WebApp doesn't work.

Edit:

I tried this, but also it did not work:


    export const deleteProduct= async (product) => {

    const params = JSON.stringify({
    "name_group":product.name_group,
    "UMB": product.UMB
    });

    const config = {
      headers: {
        "content-type": "application/json",
      },
      body: params
     
    }

    return await axios.delete("https://anyDomanin.cloud/Inventory/products/", config);
};

Victor Potes
  • 101
  • 1
  • 1
  • 8
  • 1
    Why are you stringifying the params? – Emile Bergeron Oct 08 '20 at 16:56
  • 1
    `axios.delete` doesn't accept request body as the second argument. Put `body: params` in the config object. – Guy Incognito Oct 08 '20 at 17:05
  • @EmileBergeron I have to send the data to the server in this format, that's how it's worked with the Create, Update and Get requests, but I have this issue when I try to make the delete request. – Victor Potes Oct 08 '20 at 17:18
  • @GuyIncognito I tried it, but the issue still appears. – Victor Potes Oct 08 '20 at 17:19
  • 1
    You'll have to show the code you tried. If it's the exact same error message, you didn't remove the second parameter. – Guy Incognito Oct 08 '20 at 17:21
  • According to the axios doc, you can pass the object directly through the `data` property of the config object: `axios.delete(url, { data: { name_group: product.name_group, /*etc*/ } });` – Emile Bergeron Oct 08 '20 at 17:23
  • @GuyIncognito You can see now the change I've made. – Victor Potes Oct 08 '20 at 17:26
  • @EmileBergeron now the issue does not appear, but I can see the data is not catched by the server. You all were right, it's only two parameters, but it does not matter how I send the data either called data or body, it is not working yet. – Victor Potes Oct 08 '20 at 17:47
  • It's a new problem and we can't really help without a [mcve]. You should investigate and open a new question if the problem persists. – Emile Bergeron Oct 08 '20 at 18:00
  • 1
    You're right, thank you anyway. However, I could solve it following the design proposed by an user in this link https://github.com/axios/axios/issues/897 – Victor Potes Oct 08 '20 at 20:11

1 Answers1

4

I could solve it following the next structure:

   return await axios({
        method: 'DELETE',
        url: 'https://anyDomanin.cloud/Inventory/products/',
        data: {
        name_group: product.name_group,
        UMB: product.UMB
        }
      })

I am based on the solution proposed by Christilut in the following link: https://github.com/axios/axios/issues/897

Victor Potes
  • 101
  • 1
  • 1
  • 8