Skip to content

Commit 6af890a

Browse files
committed
fix: switch error code from 404 to 401 when api key is invalid
1 parent 922c2f9 commit 6af890a

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

cli/src/components/referral-banner.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ export const ReferralBanner = () => {
99
const theme = useTheme()
1010
const setInputMode = useChatStore((state) => state.setInputMode)
1111

12-
const { data: userDetails, isLoading, isError } = useUserDetailsQuery({
12+
const { data: userDetails, isLoading, isError, error } = useUserDetailsQuery({
1313
fields: ['referral_link'] as const,
1414
enabled: true,
1515
})
1616

1717
const referralLink = userDetails?.referral_link ?? null
18+
const isAuthError = error?.message?.includes('401')
19+
1820
let text = ''
1921
if (isLoading) text = 'Loading your referral link...'
22+
else if (isAuthError) text = 'Session expired. Please log in again to view your referral link.'
2023
else if (isError) text = 'Failed to load your referral link. Please try again later.'
2124
else if (!referralLink) text = 'Your referral link is not available yet'
2225
else text = `Share this link with friends:\n${referralLink}`

web/src/app/api/v1/me/__tests__/me.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe('/api/v1/me route', () => {
105105
expect(body).toEqual({ id: 'user-123' })
106106
})
107107

108-
test('returns 404 when API key is invalid', async () => {
108+
test('returns 401 when API key is invalid', async () => {
109109
const req = new NextRequest('http://localhost:3000/api/v1/me', {
110110
headers: { Authorization: 'Bearer invalid-key' },
111111
})
@@ -114,7 +114,7 @@ describe('/api/v1/me route', () => {
114114
...agentRuntimeImpl,
115115
req,
116116
})
117-
expect(response.status).toBe(404)
117+
expect(response.status).toBe(401)
118118
const body = await response.json()
119119
expect(body).toEqual({ error: 'Invalid API key or user not found' })
120120
})

web/src/app/api/v1/me/_get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export async function getMe(params: {
113113
if (!userInfo) {
114114
return NextResponse.json(
115115
{ error: 'Invalid API key or user not found' },
116-
{ status: 404 },
116+
{ status: 401 },
117117
)
118118
}
119119

0 commit comments

Comments
 (0)