Umbro
Umbro

Reputation: 2204

Axios.delete in React: `Error:DELETE chrome-extension://...`

I create the chrome extension in React . During request url delete, I received an error: Error: DELETE chrome-extension://ldkflkflkfklfkfksfk/[object%20Object] net::ERR_FILE_NOT_FOUND

I tried to do the Get method earlier. This method works. Also token, url are good.

In tab network in response headers I have Provisional headers are shown

delete = (id) => {

    const url = `https://applic.com/api/v1/todos/${id}?expand=createdBy`;
    const token = '12345'; 

    axios.delete({
      url: url,
      headers: { 'Authorization' : `Bearer ${token}` }
    }).then(function(response) {
      console.log(`Deleted: ${id}` );
    }).catch(function (error) {
      console.log(`error: ${id}`);
    });

    const filter = this.state.items.filter(item=> item.id !== id);

    this.setState({ 
      items: filter,
      isOpen: false
    });
}

Upvotes: 0

Views: 170

Answers (1)

Agney
Agney

Reputation: 19224

The syntax for axios.delete is axios.delete(url[, config])

The API call should be:

axios.delete(
  url,
  { 
     headers: { 'Authorization' : `Bearer ${token}`
  }
})

Docs

Upvotes: 1

Related Questions