()
| 11 | } from './actions'; |
| 12 | |
| 13 | function* fetchSessionUser() { |
| 14 | const timeoutTask = yield fork(function* () { |
| 15 | // The server should not take anywhere near 2 seconds to respond. If it |
| 16 | // does, we assume the request has failed and dispatch a timeout action to |
| 17 | // dismiss the loading state. |
| 18 | yield delay(2000); |
| 19 | yield put(fetchUserTimeout()); |
| 20 | }); |
| 21 | |
| 22 | try { |
| 23 | // This is on a longer timeout to make sure that users with slow connections |
| 24 | // do, eventually, get signed in. |
| 25 | const res = yield call(getSessionUser, AbortSignal.timeout(10000)); |
| 26 | |
| 27 | const isSignedOut = res.response.status === 401; |
| 28 | if (!res.response.ok && !isSignedOut) { |
| 29 | throw new Error( |
| 30 | `HTTP Error: ${res.response.status} ${res.response.statusText}` |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | const { data: user } = res; |
| 35 | yield put(fetchUserComplete({ user })); |
| 36 | } catch (e) { |
| 37 | console.log('failed to fetch user', e); |
| 38 | const handledError = wrapHandledError(e, UserFetchErrorMessage); |
| 39 | yield put(fetchUserError(handledError)); |
| 40 | } finally { |
| 41 | yield cancel(timeoutTask); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | function* fetchOtherUser({ payload: maybeUser = '' }) { |
| 46 | try { |
nothing calls this directly
no test coverage detected