Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} 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
});
}
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(
// 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
});
}
}