Skip to content

Commit

Permalink
feat: Display connection and polling of models error
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-cucu committed Jan 17, 2024
1 parent 5e8ef26 commit 48053bf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 34 deletions.
17 changes: 2 additions & 15 deletions src/store/app/thunks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
jujuStateFactory,
} from "testing/factories/juju/juju";

import { logOut, connectAndStartPolling, connectAndListModels } from "./thunks";
import { logOut, connectAndStartPolling } from "./thunks";

describe("thunks", () => {
it("logOut", async () => {
Expand Down Expand Up @@ -40,19 +40,6 @@ describe("thunks", () => {
});

it("connectAndStartPolling", async () => {
const action = connectAndStartPolling();
const dispatch = jest.fn();
const getState = jest.fn(() => rootStateFactory.build());
await action(dispatch, getState, null);
const dispatchedThunk = await dispatch.mock.calls[1][0](
dispatch,
getState,
null,
);
expect(dispatchedThunk.type).toBe("app/connectAndListModels/fulfilled");
});

it("connectAndListModels", async () => {
const dispatch = jest.fn();
const getState = jest.fn(() =>
rootStateFactory.build({
Expand Down Expand Up @@ -87,7 +74,7 @@ describe("thunks", () => {
}),
}),
);
const action = connectAndListModels();
const action = connectAndStartPolling();
await action(dispatch, getState, null);
expect(dispatch).toHaveBeenCalledWith(
appActions.connectAndPollControllers({
Expand Down
21 changes: 5 additions & 16 deletions src/store/app/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,6 @@ export const connectAndStartPolling = createAsyncThunk<
state: RootState;
}
>("app/connectAndStartPolling", async (_, thunkAPI) => {
try {
await thunkAPI.dispatch(connectAndListModels());
} catch (error) {
// XXX Add to Sentry.
console.error("Error while trying to connect and list models.", error);
}
});

export const connectAndListModels = createAsyncThunk<
void,
void,
{
state: RootState;
}
>("app/connectAndListModels", async (_, thunkAPI) => {
try {
const storeState = thunkAPI.getState();
const config = getConfig(storeState);
Expand Down Expand Up @@ -93,10 +78,14 @@ export const connectAndListModels = createAsyncThunk<
}),
);
} catch (error) {
// XXX Surface error to UI.
// XXX Send to sentry if it's an error that's not connection related
// a common error returned by this is:
// Something went wrong: cannot send request {"type":"ModelManager","request":"ListModels","version":5,"params":...}: connection state 3 is not open
console.error("Something went wrong: ", error);
thunkAPI.dispatch(

Check warning on line 85 in src/store/app/thunks.ts

View check run for this annotation

Codecov / codecov/patch

src/store/app/thunks.ts#L85

Added line #L85 was not covered by tests
generalActions.storeConnectionError(
"Error while triggering the connection and polling of models.",
),
);
}
});
3 changes: 0 additions & 3 deletions src/store/middleware/check-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ export const checkAuthMiddleware: Middleware<
];

const thunkAllowlist = [
appThunks.connectAndListModels.fulfilled.type,
appThunks.connectAndListModels.pending.type,
appThunks.connectAndListModels.rejected.type,
appThunks.connectAndStartPolling.fulfilled.type,
appThunks.connectAndStartPolling.pending.type,
appThunks.connectAndStartPolling.rejected.type,
Expand Down

0 comments on commit 48053bf

Please sign in to comment.