How to use the redux-api-middleware/lib/util.normalizeTypeDescriptors 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
// Do not process actions without a [RSAA] property
    if (!isMockRSAA(action)) {
      return next(action);
    }

    // Try to dispatch an error request FSA for invalid RSAAs
    const validationErrors = validateMockRSAA(action);
    if (validationErrors.length) {
      throw validationErrors;
    }

    // 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