How to use the redux-api-middleware/lib/errors.RequestError function in redux-api-middleware

To help you get started, we’ve selected a few redux-api-middleware examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dremio / dremio-oss / dac / ui / src / mockApi / middleware.js View on Github external
} catch (e) {
      return next({
        ...requestType,
        payload: new RequestError('[RSAA].bailout function failed'),
        error: true
      });
    }

    // Process [RSAA].endpoint function
    if (typeof endpoint === 'function') {
      try {
        endpoint = endpoint(getState());
      } catch (e) {
        return next({
          ...requestType,
          payload: new RequestError('[RSAA].endpoint function failed'),
          error: true
        });
      }
    }

    // Process [RSAA].headers function
    if (typeof headers === 'function') {
      try {
        headers = headers(getState());
      } catch (e) {
        return next({
          ...requestType,
          payload: new RequestError('[RSAA].headers function failed'),
          error: true
        });
      }
github dremio / dremio-oss / dac / ui / src / mockApi / middleware.js View on Github external
return next({
          ...requestType,
          payload: new RequestError('[RSAA].endpoint function failed'),
          error: true
        });
      }
    }

    // Process [RSAA].headers function
    if (typeof headers === 'function') {
      try {
        headers = headers(getState());
      } catch (e) {
        return next({
          ...requestType,
          payload: new RequestError('[RSAA].headers function failed'),
          error: true
        });
      }
    }

    // We can now dispatch the request FSA
    dispatch(requestType);

    // get fake response
    const res = getMockResponse(action);

    await sleep(1000);

    // Process the server response
    if (res.ok) {
      return next(await actionWith(
github dremio / dremio-oss / dac / ui / src / mockApi / middleware.js View on Github external
// Parse the validated RSAA action
    const callAPI = action[CALL_MOCK_API];
    let { endpoint, headers } = callAPI;
    const { bailout, types } = callAPI;
    const [requestType, successType, failureType] = normalizeTypeDescriptors(types);

    // Should we bail out?
    try {
      if ((typeof bailout === 'boolean' && bailout) ||
          (typeof bailout === 'function' && bailout(getState()))) {
        return;
      }
    } catch (e) {
      return next({
        ...requestType,
        payload: new RequestError('[RSAA].bailout function failed'),
        error: true
      });
    }

    // Process [RSAA].endpoint function
    if (typeof endpoint === 'function') {
      try {
        endpoint = endpoint(getState());
      } catch (e) {
        return next({
          ...requestType,
          payload: new RequestError('[RSAA].endpoint function failed'),
          error: true
        });
      }
    }