File tree Expand file tree Collapse file tree
packages/mcp-cloudflare/src/server/oauth Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ describe("tokenExchangeCallback", () => {
3737 expect ( mockFetch ) . not . toHaveBeenCalled ( ) ;
3838 } ) ;
3939
40- it ( "should throw error when no refresh token in props" , async ( ) => {
40+ it ( "should return undefined when no refresh token in props" , async ( ) => {
4141 const options : TokenExchangeCallbackOptions = {
4242 grantType : "refresh_token" ,
4343 clientId : "test-client-id" ,
@@ -51,9 +51,9 @@ describe("tokenExchangeCallback", () => {
5151 } as WorkerProps ,
5252 } ;
5353
54- await expect ( tokenExchangeCallback ( options , mockEnv ) ) . rejects . toThrow (
55- "No refresh token available in stored props" ,
56- ) ;
54+ await expect (
55+ tokenExchangeCallback ( options , mockEnv ) ,
56+ ) . resolves . toBeUndefined ( ) ;
5757 expect ( mockFetch ) . not . toHaveBeenCalled ( ) ;
5858 } ) ;
5959
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import type { z } from "zod";
66import { logError } from "@sentry/mcp-server/logging" ;
77import { TokenResponseSchema , SENTRY_TOKEN_URL } from "./constants" ;
88import type { WorkerProps } from "../types" ;
9+ import * as Sentry from "@sentry/cloudflare" ;
910
1011/**
1112 * Constructs an authorization URL for Sentry.
@@ -223,11 +224,16 @@ export async function tokenExchangeCallback(
223224 return undefined ; // No-op for other grant types
224225 }
225226
227+ Sentry . setUser ( { id : options . props . id , name : options . props . name } ) ;
228+
226229 // Extract the refresh token from the stored props
227230 const currentRefreshToken = options . props . refreshToken ;
228-
229231 if ( ! currentRefreshToken ) {
230- throw new Error ( "No refresh token available in stored props" ) ;
232+ Sentry . captureException (
233+ new Error ( "No refresh token available in stored props" ) ,
234+ ) ;
235+
236+ return undefined ;
231237 }
232238
233239 try {
You can’t perform that action at this time.
0 commit comments