-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathfetchUserSubscriptionsFactory.ts
More file actions
44 lines (37 loc) · 1.14 KB
/
fetchUserSubscriptionsFactory.ts
File metadata and controls
44 lines (37 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as actionTypes from '../../actionTypes.js';
import {
type GetSubscriptions,
toBlackoutError,
} from '@farfetch/blackout-client';
import type { FetchUserSubscriptionsFactory } from './types/index.js';
/**
* @deprecated Prefer to use `fetchUserSubscriptionsFactoryVNext`
* Method to create a thunk factory configured with the specified client.
*
* @param getSubscriptions - Get subscriptions client.
*
* @returns Thunk factory.
*/
const fetchUserSubscriptionsFactory: FetchUserSubscriptionsFactory<
GetSubscriptions
> = getSubscriptions => (query, config) => async dispatch => {
try {
dispatch({
type: actionTypes.FETCH_USER_SUBSCRIPTIONS_REQUEST,
});
const result = await getSubscriptions(query, config);
dispatch({
payload: result,
type: actionTypes.FETCH_USER_SUBSCRIPTIONS_SUCCESS,
});
return result;
} catch (error) {
const errorAsBlackoutError = toBlackoutError(error);
dispatch({
payload: { error: errorAsBlackoutError },
type: actionTypes.FETCH_USER_SUBSCRIPTIONS_FAILURE,
});
throw errorAsBlackoutError;
}
};
export default fetchUserSubscriptionsFactory;