Skip to content

Commit 8dbd698

Browse files
committed
enhance error handling and also handle UI staus when API is calling
1 parent b97cd66 commit 8dbd698

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src-react/actions/ungit-config.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
11
import * as types from 'constants/action-types';
2+
23
export function fetchUngitConfig() {
34
return dispatch => {
5+
dispatch(pending());
46
// consider wrap API call in separate modules
57
// it will be easy to stub module's function when testing
68
fetch('http://localhost:8448/ungit/config')
79
.then(response => response.json())
810
.then(json => {
911
dispatch(receiveUgitConfig(json));
12+
})
13+
.catch(e => {
14+
dispatch(apiError(e.message));
1015
});
1116
};
1217
};
1318

1419
export function receiveUgitConfig(ungitConfig) {
1520
return {
1621
type: types.RECEIVE_UNGIT_CONFIG,
17-
ungitConfig
22+
payload: ungitConfig
23+
};
24+
};
25+
26+
export function pending() {
27+
return {
28+
type: types.PATH_PAGE_PENDING
29+
};
30+
};
31+
32+
export function apiError(message) {
33+
return {
34+
type: types.PATH_PAGE_API_ERR,
35+
payload: message
1836
};
19-
};
37+
}

src-react/constants/action-types.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export const RECEIVE_UNGIT_CONFIG = 'RECEIVE_UNGIT_CONFIG';
1+
export const RECEIVE_UNGIT_CONFIG = 'RECEIVE_UNGIT_CONFIG';
2+
export const PATH_PAGE_PENDING = 'PATH_PAGE_PENDING';
3+
export const PATH_PAGE_API_ERR = 'PATH_PAGE_API_ERR';

0 commit comments

Comments
 (0)