相关文章推荐
很拉风的单杠  ·  java.lang.NoClassDefFo ...·  6 月前    · 
聪明的啤酒  ·  [Solved] ...·  6 月前    · 
失恋的充电器  ·  ONNX Runtime ...·  8 月前    · 
长情的企鹅  ·  Java中File的delete() ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Really odd issue I am having. For some reason my put in my catch block is not being executed below. Here's my saga:

function* postLoginFormSaga(action) {
    let response;
    try {
        // Data from emitting login action
        response = yield call(AuthenticationApi.login, action.formData);
        yield put(createLoginSucceedAction());
        yield put(push('/dashboard/summary'));
    } catch (e) {
        console.log(e);
        yield put(createLoginFailAction(response))

And my api call, which has a custom middleware to handle non 2XX responses:

static login = (formData) => {
        return fetch('/api/login', {
            method: 'POST',
            body: formData,
            credentials: 'same-origin'
        }).then(handleFetchErrorMiddleWare)
            .then(r => r.json())

Where the middleware function is a simple function that checks the ok property of the response object:

export function handleFetchErrorMiddleWare(response) {
    if (!response.ok){
        throw Error(response.status)
    return response

The middleware is working correctly as I can see the output of the console.log(e) when an exception is thrown, but the yield put(createLoginFailAction(response)) is not being emitted ... See below:

Any ideas? Thanks

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.