-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api error): catch failed to fetch errors and let the user know
- refactors `apiActionTypes` and `isApiAction` to `utils/actionTypes` file - fix all imports - moved `apiConnection` to new `Connection` store - add `failedToFetchCount` to `Connection` store - remove `setApiConnection` func - add `Connection` reducer - add `FAILED_TO_FETCH` action type to `Connection` reducer - test for failed to fetch errors in `apiMiddleware`, send action with type `FAILED_TO_FETCH` - catch `FAILED_TO_FETCH` actions in `Connection` reducer, increment `failedToFetchCount` each time. Set `apiConnection` to -1 after 15 tries - catch all api success actions in the `Connection` reducer. On api success, set `apiConnection` to 1 and reset `failedToFetchCount`
- Loading branch information
1 parent
e7c3b88
commit 57011a4
Showing
2 changed files
with
12 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
export const getActionType = (action = { type: '' }): string => { | ||
if (action.type.includes('REQUEST')) return 'request' | ||
if (action.type.includes('SUCCESS')) return 'success' | ||
if (action.type.includes('FAILURE')) return 'failure' | ||
return '' | ||
} | ||
|
||
export function apiActionTypes (endpoint: string): [string, string, string] { | ||
const name = endpoint.toUpperCase() | ||
return [`API_${name}_REQUEST`, `API_${name}_SUCCESS`, `API_${name}_FAILURE`] | ||
} | ||
|
||
export const getActionType = (action = { type: '' }): string => { | ||
if (action.type.endsWith('REQUEST')) return 'request' | ||
if (action.type.endsWith('SUCCESS')) return 'success' | ||
if (action.type.endsWith('FAILURE')) return 'failure' | ||
return '' | ||
} | ||
|
||
export function isApiAction (action = { type: '' }): boolean { | ||
return !!action.type && action.type.startsWith('API') | ||
export function isApiAction (endpoint: string): boolean { | ||
return endpoint.includes('API') | ||
} |