Skip to content

Commit fd1e5bf

Browse files
committed
refactor(auth): update error handling for missing Google refresh tokens
- Replaced instances of UserError.MissingGoogleField with UserError.MissingGoogleRefreshToken across multiple files to improve clarity in error reporting. - Updated tests in google.auth.service.test.ts, google.guard.test.ts, and google.required.middleware.test.ts to reflect the new error handling logic. - Enhanced UserError definitions in user.errors.ts to provide more specific feedback regarding missing Google refresh tokens.
1 parent c0ba1ce commit fd1e5bf

6 files changed

Lines changed: 9 additions & 9 deletions

File tree

packages/backend/src/auth/services/google.auth.service.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("getGcalClient", () => {
3434
mockFindCompassUserBy.mockResolvedValue(userWithoutGoogle);
3535

3636
await expect(getGcalClient(userId)).rejects.toMatchObject({
37-
description: UserError.MissingGoogleField.description,
37+
description: UserError.MissingGoogleRefreshToken.description,
3838
});
3939

4040
expect(mockFindCompassUserBy).toHaveBeenCalledWith("_id", userId);
@@ -59,7 +59,7 @@ describe("getGcalClient", () => {
5959
mockFindCompassUserBy.mockResolvedValue(userWithEmptyGoogle);
6060

6161
await expect(getGcalClient(userId)).rejects.toMatchObject({
62-
description: UserError.MissingGoogleField.description,
62+
description: UserError.MissingGoogleRefreshToken.description,
6363
});
6464
});
6565

packages/backend/src/auth/services/google.auth.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const getGAuthClientForUser = async (
4545

4646
if (!_user?.google?.gRefreshToken) {
4747
throw error(
48-
UserError.MissingGoogleField,
48+
UserError.MissingGoogleRefreshToken,
4949
"User has not connected Google Calendar",
5050
);
5151
}
@@ -114,7 +114,7 @@ export const getGcalClient = async (userId: string): Promise<gCalendar> => {
114114

115115
if (!user.google?.gRefreshToken) {
116116
throw error(
117-
UserError.MissingGoogleField,
117+
UserError.MissingGoogleRefreshToken,
118118
"User has not connected Google Calendar",
119119
);
120120
}

packages/backend/src/common/errors/user/user.errors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ErrorMetadata } from "@backend/common/types/error.types";
33

44
interface UserErrors {
55
InvalidValue: ErrorMetadata;
6-
MissingGoogleField: ErrorMetadata;
6+
MissingGoogleRefreshToken: ErrorMetadata;
77
MissingUserIdField: ErrorMetadata;
88
UserNotFound: ErrorMetadata;
99
}
@@ -14,7 +14,7 @@ export const UserError: UserErrors = {
1414
status: Status.BAD_REQUEST,
1515
isOperational: true,
1616
},
17-
MissingGoogleField: {
17+
MissingGoogleRefreshToken: {
1818
description: "User is missing a Google refresh token",
1919
status: Status.BAD_REQUEST,
2020
isOperational: true,

packages/backend/src/common/guards/google.guard.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe("google.guard", () => {
142142
mockFindCompassUserBy.mockResolvedValue(userWithoutGoogle);
143143

144144
await expect(requireGoogleConnection(userId)).rejects.toMatchObject({
145-
description: UserError.MissingGoogleField.description,
145+
description: UserError.MissingGoogleRefreshToken.description,
146146
});
147147
});
148148
});

packages/backend/src/common/guards/google.guard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const requireGoogleConnection = async (
1616
}
1717
if (!(await isGoogleConnected(userId))) {
1818
throw error(
19-
UserError.MissingGoogleField,
19+
UserError.MissingGoogleRefreshToken,
2020
"User has not connected Google Calendar",
2121
);
2222
}

packages/backend/src/common/middleware/google.required.middleware.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe("google.required.middleware", () => {
7676
};
7777
const baseError = new BaseError(
7878
"User has not connected Google Calendar",
79-
UserError.MissingGoogleField.description,
79+
UserError.MissingGoogleRefreshToken.description,
8080
Status.BAD_REQUEST,
8181
true,
8282
);

0 commit comments

Comments
 (0)