'How I can custom axios in Vue

I wrote a response with an axios interceptors and send the return value of this response to a js file named handleResponse. This js file takes the return value and returns a result to me. If I get an error, I have it drop to reject.

  const instance = axios.create({
        baseURL:
            apiName === ""
                ? process.env.VUE_APP_API_URL
                : process.env.VUE_APP_API_URL + apiName,
        withCredentials: false,
        headers: headers
    });


    instance.interceptors.response.use(
        (response) => handleResponse(response),
        (error) => console.log(error)
    );

My handleResponse js file inside interceptors is as follows

export const handleResponse = (response) => {
    return new Promise((resolve) => {
        if (response.data["Success"]) resolve(response.data["Payload"]);
        else {
            let msg = "";
            if (response.data["Information"]) msg = response.data["Information"];

            showError(msg);
             reject(response);
        }
    });
};

Here I make it fall into catch where I call the api when it drops to the reject operation.

   const cancelStorageTransfer = () => {
      return StorageTransferRequestService.cancelStorageTransfer(selectedStorageTransfer.value.Id)
          .then(() => {
            showSuccess("Transfer İptal İşlemi Başarıyla Gerçekleşti")
            storageTransferRequestSummary()
          }).catch(response => {
            showError(response.data.Information)
          })
    }

I call the api here, but I don't want to use the catch. But when I don't use it, I get "Uncauth(in promise)" error on the log screen.

Here how can I do whether to use the catch at my own will?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source