Skip to content

Commit

Permalink
fix: handle error sidecar API (#2269)
Browse files Browse the repository at this point in the history
Fix #2169 
Co-authored-by: Chandrasekhar Ramakrishnan <[email protected]>
  • Loading branch information
andre-code authored Jan 10, 2023
1 parent d3f4fe9 commit 8f0f3cd
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
12 changes: 10 additions & 2 deletions client/src/features/session/sidecarApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";

type HealthState = { status: string };
type HealthState = { status: string,
error?: {
code: number;
message: string;
};
};

interface SidecarRequestArgs {
serverName: string;
Expand All @@ -24,6 +29,10 @@ interface GitStatusResult extends JsonRpcResult {
commit: string;
status: string;
};
error?: {
code: number;
message: string;
};
}

interface RenkuOpResult extends JsonRpcResult {
Expand All @@ -36,7 +45,6 @@ interface RenkuOpResult extends JsonRpcResult {

interface SaveResult extends RenkuOpResult {}
interface PullResult extends RenkuOpResult {}

export const sessionSidecarApi = createApi({
reducerPath: "sessionSidecarApi",
baseQuery: fetchBaseQuery({ baseUrl: "/sessions/" }),
Expand Down
6 changes: 3 additions & 3 deletions client/src/notebooks/components/PullSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function RunningPullSessionBody(props: PullSessionProps) {
if (isLoading)
body = <CenteredLoader />;

else if (error != null || data == null || data.status !== "running")
else if (error != null || data == null || data.status !== "running" || data.error)
body = <NoSidecarBody closeModal={closeModal} />;

else body = <PullSessionStatusBody closeModal={closeModal} isOpen={isOpen} sessionName={serverName} />;
Expand Down Expand Up @@ -97,9 +97,9 @@ function PullSessionStatusBody({ closeModal, isOpen, sessionName }: PullSessionS
};

if (isFetching || data == null) return <CenteredLoader />;
if (error) return <NoSidecarBody closeModal={closeModal} />;
if (error || data.error) return <NoSidecarBody closeModal={closeModal} />;
if (succeeded === false) return <PullSessionFailedBody closeModal={closeModal} />;
if (succeeded === true) return <PullSessionUpToDateBody closeModal={closeModal}/>;
if (succeeded === true) return <PullSessionUpToDateBody closeModal={closeModal} />;
if (data.result.behind < 1) return <PullSessionUpToDateBody closeModal={closeModal} />;
if (!data.result.clean || data.result.ahead > 0)
return <PullSessionDivergedBody clean={data.result.clean} closeModal={closeModal} />;
Expand Down
4 changes: 2 additions & 2 deletions client/src/notebooks/components/SaveSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function RunningSaveSessionBody(props: SaveSessionProps) {
else if (isLoading)
body = <CenteredLoader />;

else if (error != null || data == null || data.status !== "running")
else if (error != null || data == null || data.status !== "running" || data.error)
body = <NoSidecarBody closeModal={closeModal} />;

else body = <SaveSessionStatusBody closeModal={closeModal} isOpen={isOpen} sessionName={serverName} />;
Expand Down Expand Up @@ -118,7 +118,7 @@ function SaveSessionStatusBody({ closeModal, isOpen, sessionName }: SaveSessionS
};

if (isFetching || data == null) return <CenteredLoader />;
if (error) return <NoSidecarBody closeModal={closeModal} />;
if (error || data.error) return <NoSidecarBody closeModal={closeModal} />;
if (data.result.behind > 0)
return <SaveSessionNoFFBody closeModal={closeModal} gitStatus={data} isOpen={isOpen} sessionName={sessionName} />;
if (succeeded === false) return <SaveSessionFailedBody closeModal={closeModal} />;
Expand Down
11 changes: 11 additions & 0 deletions tests/cypress/e2e/local/session.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ describe("display a session", () => {
.contains("It is not possible to offer a one-click refresh for this session.").should("be.visible");
});

it("pull changes button -- sidecar error`", () => {
fixtures.getSidecarHealth().getGitStatusError();
cy.gui_open_session();
// pull changes
cy.get_cy("pull-changes-button").click();
cy.get(".modal-dialog").should("exist");
cy.get(".modal-dialog").get("h5").contains("Refresh Session").should("be.visible");
cy.get(".modal-dialog").get("div")
.contains("It is not possible to offer a one-click refresh for this session.").should("be.visible");
});

it("pull changes button -- session clean", () => {
fixtures.getSidecarHealth().getGitStatusClean();
cy.gui_open_session();
Expand Down
20 changes: 19 additions & 1 deletion tests/cypress/support/renkulab-fixtures/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,26 @@ function Sessions<T extends FixturesConstructor>(Parent: T) {
).as(name);
return this;
}
};

getGitStatusError(name = "getGitStatus") {
const fixture = {
body: {
"error": {
"code": -32000,
// eslint-disable-next-line max-len
"message": "Running a git command failed with the error: fatal: could not read Username for 'https://gitlab.dev.renku.ch': No such device or address\n"
},
"id": 0,
"jsonrpc": "2.0"
} };

cy.intercept(
"/sessions/*/sidecar/jsonrpc",
fixture
).as(name);
return this;
}
};
}

export { Sessions };

0 comments on commit 8f0f3cd

Please sign in to comment.