Skip to content

Commit 8b1bb9b

Browse files
committed
chore: add logs to understand GitHub OAuth failure
Relative to ARGOS-SERVER-XR5
1 parent 115ad9f commit 8b1bb9b

File tree

1 file changed

+27
-30
lines changed

1 file changed

+27
-30
lines changed

apps/backend/src/github/auth.ts

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import * as Sentry from "@sentry/node";
21
import axios from "axios";
32
import { z } from "zod";
43

4+
import logger from "@/logger";
5+
56
const RetrieveTokenResponseSchema = z.object({
67
access_token: z.string(),
78
token_type: z.literal("bearer"),
@@ -14,36 +15,32 @@ export async function retrieveOAuthToken(args: {
1415
code: string;
1516
redirectUri: string;
1617
}) {
17-
return Sentry.withScope(async (scope) => {
18-
const body = {
19-
client_id: args.clientId,
20-
client_secret: args.clientSecret,
21-
code: args.code,
22-
redirect_uri: args.redirectUri,
23-
};
24-
25-
scope.setExtra("body", body);
18+
const body = {
19+
client_id: args.clientId,
20+
client_secret: args.clientSecret,
21+
code: args.code,
22+
redirect_uri: args.redirectUri,
23+
};
2624

27-
const result = await axios.post(
28-
"https://github.com/login/oauth/access_token",
29-
body,
30-
{
31-
headers: {
32-
accept: "application/json",
33-
},
25+
const result = await axios.post(
26+
"https://github.com/login/oauth/access_token",
27+
body,
28+
{
29+
headers: {
30+
accept: "application/json",
3431
},
35-
);
32+
},
33+
);
3634

37-
try {
38-
return RetrieveTokenResponseSchema.parse(result.data);
39-
} catch (error) {
40-
scope.setExtra("errorResponse", {
41-
status: result.status,
42-
data: result.data,
43-
});
44-
throw new Error("Failed to parse GitHub OAuth response", {
45-
cause: error,
46-
});
47-
}
48-
});
35+
try {
36+
return RetrieveTokenResponseSchema.parse(result.data);
37+
} catch (error) {
38+
logger.info("GitHub OAuth response errored", {
39+
status: result.status,
40+
data: result.data,
41+
});
42+
throw new Error("Failed to parse GitHub OAuth response", {
43+
cause: error,
44+
});
45+
}
4946
}

0 commit comments

Comments
 (0)