Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WD-8294 - feat: Display connection and polling of models error #1682

Merged
merged 8 commits into from
Jan 24, 2024
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
31 changes: 12 additions & 19 deletions src/store/app/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

import type { ControllerArgs } from "./actions";

enum Label {
CONNECT_AND_START_POLLING_ERROR = "Error while triggering the connection and polling of models.",
}

export const logOut = createAsyncThunk<
void,
void,
Expand Down Expand Up @@ -51,21 +55,6 @@
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 +82,14 @@
}),
);
} 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);
// a common error logged to the console by this is:
// Error while triggering the connection and polling of models. cannot send request {"type":"ModelManager","request":"ListModels","version":5,"params":...}: connection state 3 is not open
console.error(Label.CONNECT_AND_START_POLLING_ERROR, error);
thunkAPI.dispatch(

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

View check run for this annotation

Codecov / codecov/patch

src/store/app/thunks.ts#L88-L89

Added lines #L88 - L89 were not covered by tests
generalActions.storeConnectionError(
Label.CONNECT_AND_START_POLLING_ERROR,
),
);
}
});
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
Loading