1
- import * as Sentry from "@sentry/node" ;
2
1
import axios from "axios" ;
3
2
import { z } from "zod" ;
4
3
4
+ import logger from "@/logger" ;
5
+
5
6
const RetrieveTokenResponseSchema = z . object ( {
6
7
access_token : z . string ( ) ,
7
8
token_type : z . literal ( "bearer" ) ,
@@ -14,36 +15,32 @@ export async function retrieveOAuthToken(args: {
14
15
code : string ;
15
16
redirectUri : string ;
16
17
} ) {
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
+ } ;
26
24
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" ,
34
31
} ,
35
- ) ;
32
+ } ,
33
+ ) ;
36
34
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
+ }
49
46
}
0 commit comments