Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Solved] ERROR action not triggered #311

Closed
strdr4605 opened this issue Jan 31, 2020 · 3 comments
Closed

[Solved] ERROR action not triggered #311

strdr4605 opened this issue Jan 31, 2020 · 3 comments

Comments

@strdr4605
Copy link
Contributor

@klis87, I have a bug when implementing the workaround with promises. My driver is as in #244 (comment). And the request is triggered and the SUCCESS is coming ok. But then there is an error from backend SUCCESS is triggered instead of ERROR.

I tried several options.

const requestGetUrls = (merchantId) => ({
        type: actions_1.MerchantActionEnum.API_URLS_GET_REQUEST,
        payload: {
            request: {
                url: axios_1.get('https://jsonplaceholder.typicode.com/users/11'),
            },
        },
    });
const requestGetUrls = (merchantId) => ({
        type: actions_1.MerchantActionEnum.API_URLS_GET_REQUEST,
        payload: {
            request: {
                url: webMerchantFacade.urls(merchantId),
            },
        },
    });
const requestGetUrls = (merchantId) => ({
        type: actions_1.MerchantActionEnum.API_URLS_GET_REQUEST,
        payload: {
            request: {
                url: 'https://jsonplaceholder.typicode.com/users/11',
            },
        },
        meta: {
          driver: 'axios'
        }
    });

All of the actions above resolve in SUCCESS instead of ERROR. Also, I tried networkReducer but still the same behavior.

Even with axios driver, there is the same problem. So maybe the problem is not in my driver.

Interesting is that when I pass a rejected Promise

const requestGetUrls = (merchantId) => ({
        type: actions_1.MerchantActionEnum.API_URLS_GET_REQUEST,
        payload: {
            request: {
                url: Promise.reject('error'),
            },
        },
    });

The ERROR action is triggered.

I made a dummy project https://codesandbox.io/s/redux-saga-requests-example-x4bf6 but there everything works as expected.

Maybe you have an Idea where can be the problem.

@strdr4605 strdr4605 changed the title ERROR action not triggered when using Custom Driver. ERROR action not triggered Jan 31, 2020
@strdr4605

This comment has been minimized.

@strdr4605 strdr4605 changed the title ERROR action not triggered [Solved] ERROR action not triggered Jan 31, 2020
@strdr4605
Copy link
Contributor Author

The problem was what a long time ago I wrote an interceptor.

export function* onErrorSaga(error: AxiosResponse, action: AnyAction): Iterator<AxiosResponse | Effect<any>> {
  ...
  ...
  return error;
}

and was returning the error object. But axios has a response property in the error that was interpreted by the redux-saga-requests as a legit response.

To fix the issue I changes the return value as in interceptors docs.

export function* onErrorSaga(error: AxiosResponse, action: AnyAction): Iterator<AxiosResponse | Effect<any>> {
  ...
  ...
  return { error };
}

@klis87
Copy link
Owner

klis87 commented Jan 31, 2020

@strdr4605 Thx for sharing this and I am glad you solved it!

@klis87 klis87 mentioned this issue Feb 1, 2020
44 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants