Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

199
Visualizações
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?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda