Skip to content
Snippets Groups Projects
Commit dc8bcb45 authored by esikkala's avatar esikkala
Browse files

Update error handling

parent b23e490a
No related branches found
No related tags found
No related merge requests found
......@@ -19,9 +19,9 @@ export const fetchPaginatedResults = (resultClass, facetClass, variant) => ({
type: FETCH_PAGINATED_RESULTS,
resultClass, facetClass, variant
});
export const fetchPaginatedResultsFailed = (resultClass, message) => ({
export const fetchPaginatedResultsFailed = (resultClass, error, message) => ({
type: FETCH_PAGINATED_RESULTS_FAILED,
resultClass, message
resultClass, error, message
});
export const fetchResults = (resultClass, facetClass, variant) => ({
type: FETCH_RESULTS,
......@@ -51,9 +51,9 @@ export const fetchFacet = (resultClass, id, sortBy, sortDirection) => ({
type: FETCH_FACET,
resultClass, id, sortBy, sortDirection
});
export const fetchFacetFailed = (resultClass, id, message) => ({
export const fetchFacetFailed = (resultClass, id, error, message) => ({
type: FETCH_FACET_FAILED,
resultClass, message
resultClass, id, error, message
});
export const updateFacet = ({ resultClass, id, distinctValueCount, values, flatValues, sortBy, sortDirection }) => ({
type: UPDATE_FACET,
......
......@@ -10,7 +10,7 @@ import {
FETCH_BY_URI,
FETCH_FACET,
FETCH_FACET_FAILED,
SHOW_ERROR,
//SHOW_ERROR,
updateResults,
updateInstance,
updateFacet,
......@@ -20,6 +20,8 @@ const apiUrl = (process.env.NODE_ENV === 'development')
? 'http://localhost:3001/api/'
: `http://${location.hostname}/api/`;
const backendErrorText = 'Cannot connect to MMM Knowledge Base. A data conversion process might be running. Please try again later.';
const fetchPaginatedResultsEpic = (action$, state$) => action$.pipe(
ofType(FETCH_PAGINATED_RESULTS),
withLatestFrom(state$),
......@@ -32,9 +34,10 @@ const fetchPaginatedResultsEpic = (action$, state$) => action$.pipe(
catchError(error => of({
type: FETCH_PAGINATED_RESULTS_FAILED,
resultClass: resultClass,
error: error,
message: {
text: error.xhr.statusText,
title: ''
text: backendErrorText,
title: 'Error'
}
}))
);
......@@ -50,14 +53,15 @@ const fetchResultsEpic = (action$, state$) => action$.pipe(
const requestUrl = `${apiUrl}${resultClass}/all?${params}`;
return ajax.getJSON(requestUrl).pipe(
map(response => updateResults({ resultClass: resultClass, data: response })),
catchError(error => of({
type: SHOW_ERROR,
resultClass: resultClass,
message: {
text: error.xhr.statusText,
title: ''
}
}))
// catchError(error => of({
// type: SHOW_ERROR,
// resultClass: resultClass,
// error: error,
// message: {
// text: backendErrorText,
// title: 'Error'
// }
// }))
);
})
);
......@@ -71,13 +75,13 @@ const fetchByURIEpic = (action$, state$) => action$.pipe(
const requestUrl = `${apiUrl}${resultClass}/instance/${encodeURIComponent(uri)}?${params}`;
return ajax.getJSON(requestUrl).pipe(
map(response => updateInstance({ resultClass: resultClass, instance: response })),
catchError(error => of({
type: SHOW_ERROR,
message: {
text: error.xhr.statusText,
title: ''
}
}))
// catchError(error => of({
// type: SHOW_ERROR,
// message: {
// text: error.xhr.statusText,
// title: ''
// }
// }))
);
})
);
......@@ -116,9 +120,10 @@ const fetchFacetEpic = (action$, state$) => action$.pipe(
type: FETCH_FACET_FAILED,
resultClass: action.resultClass,
id: action.id,
error: error,
message: {
text: error.xhr.statusText,
title: ''
text: backendErrorText,
title: 'Error'
}
}))
);
......
......@@ -38,13 +38,12 @@ render(
<App />
</Router>
<ReduxToastr
timeOut={4000}
timeOut={0}
newestOnTop={false}
preventDuplicates
position="top-center"
transitionIn="fadeIn"
transitionOut="fadeOut"
progressBar
/>
</div>
</Provider>,
......
......@@ -101,21 +101,13 @@ const manuscripts = (state = INITIAL_STATE, action) => {
case SORT_RESULTS:
return updateSortBy(state, action);
case UPDATE_RESULTS:
if (action.data !== null) {
return {
...state,
resultCount: parseInt(action.data.resultCount),
results: action.data.results,
fetching: false
};
} else {
return {
...state,
results: [],
resultCount: 0,
fetching: false
};
}
// console.log(action)
return {
...state,
resultCount: parseInt(action.data.resultCount),
results: action.data.results,
fetching: false
};
case UPDATE_INSTANCE:
return {
...state,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment