mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 01:15:03 +03:00
fix: preserve function responses (#47920)
- adds up to: https://github.com/supabase/cli/pull/5862 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added an “Error docs” link in Edge Function testing UI when an `sb-error-code` header is present. * **Bug Fixes** * Improved the Edge Function test proxy to consistently preserve upstream status, headers (including repeated headers), and response bodies without transformation. * Enhanced handling for invalid function URLs and upstream fetch failures. * **Tests** * Added unit, API, and Playwright E2E coverage for error docs linking and response proxy behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
1 parent
4864031466
commit
83e6552d71
7 files changed
+301
-40
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import { expect } from '@playwright/test'
|
||||
|
||||
import { test } from '../utils/test.js'
|
||||
import { toUrl } from '../utils/to-url.js'
|
||||
|
||||
const FUNCTION_SLUG = 'error-code-docs'
|
||||
|
||||
test.describe('Edge Functions', () => {
|
||||
test('links an sb-error-code response to its documentation', async ({ page, ref }) => {
|
||||
await page.route(`**/api/v1/projects/${ref}/functions/${FUNCTION_SLUG}`, async (route) => {
|
||||
const timestamp = Date.now()
|
||||
await route.fulfill({
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
id: '00000000-0000-0000-0000-000000000000',
|
||||
slug: FUNCTION_SLUG,
|
||||
name: FUNCTION_SLUG,
|
||||
version: 1,
|
||||
status: 'ACTIVE',
|
||||
entrypoint_path: `supabase/functions/${FUNCTION_SLUG}/index.ts`,
|
||||
created_at: timestamp,
|
||||
updated_at: timestamp,
|
||||
}),
|
||||
})
|
||||
})
|
||||
await page.route('**/api/edge-functions/test', async (route) => {
|
||||
await route.fulfill({
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
status: 401,
|
||||
headers: { 'sb-error-code': 'UNAUTHORIZED_INVALID_JWT_FORMAT' },
|
||||
body: '',
|
||||
}),
|
||||
})
|
||||
})
|
||||
|
||||
await page.goto(toUrl(`/project/${ref}/functions/${FUNCTION_SLUG}`))
|
||||
await page.getByRole('button', { name: 'Test', exact: true }).click()
|
||||
|
||||
const testResponse = page.waitForResponse(
|
||||
(response) =>
|
||||
response.url().includes('/api/edge-functions/test') &&
|
||||
response.request().method() === 'POST'
|
||||
)
|
||||
await page.getByRole('button', { name: 'Send Request' }).click()
|
||||
expect(
|
||||
(await testResponse).ok(),
|
||||
'Studio proxy should return a successful response envelope'
|
||||
).toBeTruthy()
|
||||
|
||||
await expect(
|
||||
page.getByRole('link', {
|
||||
name: 'View documentation for UNAUTHORIZED_INVALID_JWT_FORMAT (opens in new tab)',
|
||||
}),
|
||||
'Error response should link to its documentation section'
|
||||
).toHaveAttribute(
|
||||
'href',
|
||||
'https://supabase.com/docs/guides/functions/error-codes#unauthorizedinvalidjwtformat'
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user