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

340
Visualizações
Events handled by another saga (Redux-Saga)

I'm trying to create an error interceptor for all my sagas, after analyzing the redux-saga eventChannel I tried to create a saga like this:

export function interceptor() {
  return eventChannel(() => {
    api.interceptors.response.use(
      (response) => response,

      (error) => {
        const { response } = error;

        if ([401, 403].includes(response.status)) {
            emit(AuthCreators.logoutRequest());
        }

        return Promise.reject(error);
      }
    );

    return () => null;
  });
}

In rootSaga it is being called this way:

export default function* rootSaga() {
    return yield all([fork(interceptor), anotherSaga, anotherSaga2]);
}

This way, every time one of my other sagas has a catch the interceptor is triggered, however my emit that should trigger the logoutRequest that is in other saga is not being triggered.

  • How can the emit call other saga?
  • Is this the best way to create an error interceptor?

Already grateful

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Maybe I don't understand you question exactly but this might help you

const saga = [
anotherSaga, anotherSaga2
]

yield all(sagas.map((saga) => spawn(function* () {
        try {
            yield call(saga);
        } catch (e) {
            // console.log(e);
            // here we should store all errors in some service...
        }
    })));
about 4 years ago · Juan Pablo Isaza Relatório
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