Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function effect({ url, headers, errorCode, deserialize = true, ...params }, { auth, ...action }) {
if (url && typeof url === 'string') {
const req = {
...params,
url,
headers: { ...headers, Authorization: `Bearer ${auth}` }
};
const canDeserialize = res => res && typeof res === 'object' && res.data && deserialize;
return defaultEffect(req, action)
.then(data => (canDeserialize(data) ? new JSONAPIDeserializer(deserializeOptions).deserialize(data) : data))
.catch(err => {
if (errorCode) return Promise.reject({ msg: err, status: errorCode });
throw err;
});
}
throw new TypeError();
}