Skip to content

Commit 1781dff

Browse files
authored
Merge pull request #1014 from rust-lang/plumb-gist-error
Plumb through errors when loading/saving gists fail
2 parents 49a08d9 + 3378698 commit 1781dff

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

ui/frontend/Output/Gist.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,23 @@ import styles from './Gist.module.css';
1313

1414
const Gist: React.FC = () => {
1515
const showLoader = useSelector(selectors.showGistLoaderSelector);
16+
const error = useSelector((state: State) => state.output.gist.error);
1617

17-
return (
18-
<div>
19-
{ showLoader ? <Loader /> : <Links />}
20-
</div>
21-
);
18+
if (showLoader) {
19+
return <Loader />;
20+
}
21+
22+
if (error) {
23+
return <Error error={error} />;
24+
}
25+
26+
return <Links />;
2227
};
2328

29+
const Error: React.FC<{error: string}> = ({ error }) => (
30+
<Section kind="error" label="Errors">{error}</Section>
31+
);
32+
2433
interface CopiedProps {
2534
children: React.ReactNode;
2635
href: string;

ui/frontend/reducers/output/gist.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Draft, PayloadAction, createAsyncThunk, createSlice } from '@reduxjs/toolkit';
1+
import {
2+
Draft,
3+
PayloadAction,
4+
SerializedError,
5+
createAsyncThunk,
6+
createSlice,
7+
} from '@reduxjs/toolkit';
28
import * as z from 'zod';
39

410
import { jsonGet, jsonPost, routes } from '../../api';
@@ -22,6 +28,7 @@ interface State {
2228
channel?: Channel;
2329
mode?: Mode;
2430
edition?: Edition;
31+
error?: string;
2532
}
2633

2734
interface SuccessProps {
@@ -81,6 +88,7 @@ export const performGistSave = createAsyncThunk<SuccessProps, void, { state: Roo
8188
);
8289

8390
const pending = (state: Draft<State>) => {
91+
delete state.error;
8492
state.requestsInProgress += 1;
8593
};
8694

@@ -89,6 +97,14 @@ const fulfilled = (state: Draft<State>, action: PayloadAction<SuccessProps>) =>
8997
Object.assign(state, action.payload);
9098
};
9199

100+
const rejected = (
101+
state: Draft<State>,
102+
action: PayloadAction<unknown, string, unknown, SerializedError>,
103+
) => {
104+
state.requestsInProgress -= 1;
105+
state.error = action.error.message;
106+
};
107+
92108
const slice = createSlice({
93109
name: sliceName,
94110
initialState,
@@ -97,8 +113,10 @@ const slice = createSlice({
97113
builder
98114
.addCase(performGistLoad.pending, pending)
99115
.addCase(performGistLoad.fulfilled, fulfilled)
116+
.addCase(performGistLoad.rejected, rejected)
100117
.addCase(performGistSave.pending, pending)
101-
.addCase(performGistSave.fulfilled, fulfilled);
118+
.addCase(performGistSave.fulfilled, fulfilled)
119+
.addCase(performGistSave.rejected, rejected);
102120
},
103121
});
104122

0 commit comments

Comments
 (0)