Fix error handling

This commit is contained in:
René Pfeuffer
2020-03-09 16:53:17 +01:00
parent 85a893824c
commit 0927e3e421
2 changed files with 10 additions and 6 deletions

View File

@@ -115,8 +115,8 @@ class FileTree extends React.Component<Props, State> {
return null; return null;
} }
if (hunks.some(hunk => hunk.error)) { if (hunks[0]?.error) {
return <ErrorNotification error={hunks.map(hunk => hunk.error)[0]} />; return <ErrorNotification error={hunks[0].error} />;
} }
return ( return (
@@ -183,6 +183,7 @@ class FileTree extends React.Component<Props, State> {
</tbody> </tbody>
</table> </table>
{hunks[hunks.length - 1].loading && <Loading />} {hunks[hunks.length - 1].loading && <Loading />}
{hunks[hunks.length - 1].error && <ErrorNotification error={hunks[hunks.length - 1].error} />}
</> </>
); );
} }
@@ -210,9 +211,11 @@ const mapStateToProps = (state: any, ownProps: Props) => {
for (let i = 0; i < hunkCount; ++i) { for (let i = 0; i < hunkCount; ++i) {
const tree = getSources(state, repository, revision, path, i); const tree = getSources(state, repository, revision, path, i);
const loading = isFetchSourcesPending(state, repository, revision, path, i); const loading = isFetchSourcesPending(state, repository, revision, path, i);
const error = getFetchSourcesFailure(state, repository, revision, path, i);
hunks.push({ hunks.push({
tree, tree,
loading loading,
error
}); });
} }

View File

@@ -103,7 +103,7 @@ export function fetchSourcesFailure(
): Action { ): Action {
return { return {
type: FETCH_SOURCES_FAILURE, type: FETCH_SOURCES_FAILURE,
payload: error, payload: { hunk, pending: false, updatePending: false, error },
itemId: createItemId(repository, revision, path, "") itemId: createItemId(repository, revision, path, "")
}; };
} }
@@ -122,12 +122,13 @@ export default function reducer(
type: "UNKNOWN" type: "UNKNOWN"
} }
): any { ): any {
if (action.itemId && action.type === FETCH_SOURCES_SUCCESS) { if (action.itemId && (action.type === FETCH_SOURCES_SUCCESS || action.type === FETCH_SOURCES_FAILURE)) {
return { return {
...state, ...state,
[action.itemId + "hunkCount"]: action.payload.hunk + 1, [action.itemId + "hunkCount"]: action.payload.hunk + 1,
[action.itemId + action.payload.hunk]: { [action.itemId + action.payload.hunk]: {
sources: action.payload.sources, sources: action.payload.sources,
error: action.payload.error,
updatePending: false, updatePending: false,
pending: false pending: false
} }
@@ -220,5 +221,5 @@ export function getFetchSourcesFailure(
path: string, path: string,
hunk = 0 hunk = 0
): Error | null | undefined { ): Error | null | undefined {
return getFailure(state, FETCH_SOURCES, createItemId(repository, revision, path, "")); return state.sources[createItemId(repository, revision, path, hunk)]?.error;
} }