Skip to content

Commit 6a6052f

Browse files
authored
[server, dashboard] Map USER_DELETED properly through the API (#20796)
* [server] Fix OrganizationService.addOrUpdateMember * [server] OrganizationService test: apply withTestCtx * [server, dashboard] Replace USER_DELETED with NOT_FOUND + error details, and ensure it's properly mapped across the API
1 parent b34a9fd commit 6a6052f

File tree

19 files changed

+1573
-162
lines changed

19 files changed

+1573
-162
lines changed

components/dashboard/src/components/error-boundaries/QueryErrorBoundary.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
7+
import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
88
import { QueryErrorResetBoundary, useQueryClient } from "@tanstack/react-query";
99
import { FC } from "react";
1010
import { ErrorBoundary, FallbackProps } from "react-error-boundary";
@@ -36,7 +36,7 @@ const ExpectedQueryErrorsFallback: FC<FallbackProps> = ({ error, resetErrorBound
3636
const caughtError = error as CaughtError;
3737

3838
// user deleted needs a n explicit logout to destroy the session
39-
if (caughtError.code === ErrorCodes.USER_DELETED) {
39+
if (ApplicationError.isUserDeletedError(caughtError)) {
4040
console.log("clearing query cache for deleted user");
4141
client.clear();
4242

components/dashboard/src/components/error-boundaries/ReloadPageErrorBoundary.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Heading1, Subheading } from "../typography/headings";
1111
import { reportError } from "../../service/metrics";
1212
import { Button } from "@podkit/buttons/Button";
1313

14-
export type CaughtError = Error & { code?: number };
14+
export type CaughtError = Error & { code?: number; data?: any };
1515

1616
// Catches any unexpected errors w/ a UI to reload the page. Also reports errors to api
1717
export const ReloadPageErrorBoundary: FC = ({ children }) => {

components/dashboard/src/hooks/use-user-loader.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { UserContext } from "../user-context";
99
import { trackLocation } from "../Analytics";
1010
import { useQuery } from "@tanstack/react-query";
1111
import { noPersistence } from "../data/setup";
12-
import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
12+
import { ErrorCodes, ApplicationError } from "@gitpod/gitpod-protocol/lib/messaging/error";
1313
import { userClient } from "../service/public-api";
1414

1515
export const useUserLoader = () => {
@@ -28,10 +28,11 @@ export const useUserLoader = () => {
2828
useErrorBoundary: true,
2929
// It's important we don't retry as we want to show the login screen as quickly as possible if a 401
3030
retry: (_failureCount: number, error: Error & { code?: number }) => {
31+
const isUserDeletedError = ApplicationError.isUserDeletedError(error);
3132
return (
3233
error.code !== ErrorCodes.NOT_AUTHENTICATED &&
33-
error.code !== ErrorCodes.USER_DELETED &&
34-
error.code !== ErrorCodes.CELL_EXPIRED
34+
error.code !== ErrorCodes.CELL_EXPIRED &&
35+
!isUserDeletedError
3536
);
3637
},
3738
// docs: https://tanstack.com/query/v4/docs/react/guides/query-retries

components/gitpod-protocol/go/error.go

-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ const (
4848
// 470 User Blocked (custom status code)
4949
USER_BLOCKED = 470
5050

51-
// 471 User Deleted (custom status code)
52-
USER_DELETED = 471
53-
5451
// 472 Terms Acceptance Required (custom status code)
5552
USER_TERMS_ACCEPTANCE_REQUIRED = 472
5653

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { suite, test } from "@testdeck/mocha";
8+
import { ApplicationError, ErrorCodes } from "./error";
9+
10+
import { expect } from "chai";
11+
12+
@suite
13+
class TestApplicationError {
14+
@test public async ApplicationError_isUserDeletedError() {
15+
expect(
16+
ApplicationError.isUserDeletedError(
17+
new ApplicationError(ErrorCodes.NOT_FOUND, "not found", { userDeleted: true }),
18+
),
19+
).to.be.true;
20+
}
21+
}
22+
module.exports = new TestApplicationError();

components/gitpod-protocol/src/messaging/error.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ export namespace ApplicationError {
3636
throw e;
3737
}
3838
}
39+
40+
export function isUserDeletedError(e: any): boolean {
41+
return hasErrorCode(e) && e.code === ErrorCodes.NOT_FOUND && e.data?.userDeleted === true;
42+
}
3943
}
4044

4145
export namespace ErrorCode {
@@ -98,9 +102,6 @@ export const ErrorCodes = {
98102
// 470 User Blocked (custom status code)
99103
USER_BLOCKED: 470 as const,
100104

101-
// 471 User Deleted (custom status code)
102-
USER_DELETED: 471 as const,
103-
104105
// 472 Terms Acceptance Required (custom status code)
105106
USER_TERMS_ACCEPTANCE_REQUIRED: 472 as const,
106107

components/public-api/gitpod/v1/error.proto

+8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ message ImageBuildLogsNotYetAvailableError {}
6767

6868
message CellDisabledError {}
6969

70+
message NotFoundDetails {
71+
oneof reason {
72+
UserDeletedError user_deleted = 1;
73+
}
74+
}
75+
76+
message UserDeletedError {}
77+
7078
/*
7179
// details for INVALID_ARGUMENT status code
7280
// TODO: this is not yet implemented in the backend

components/public-api/go/v1/error.pb.go

+156-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)