{"record":{"id":"dca62784197d5c95","repo":"supabase/supabase","slug":"failed-to-test-edge-function","errorCode":null,"errorMessage":"Failed to test edge function","messagePattern":"Failed to test edge function","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/studio/data/edge-functions/edge-function-test-mutation.ts","lineNumber":37,"sourceCode":"}\n\nexport async function testEdgeFunction({ url, method, body, headers }: EdgeFunctionTestVariables) {\n  const defaultHeaders = await constructHeaders()\n\n  const response = await fetchHandler(`${BASE_PATH}/api/edge-functions/test`, {\n    method: 'POST',\n    headers: { ...defaultHeaders, 'Content-Type': 'application/json' },\n    body: JSON.stringify({ url, method, body, headers }),\n  })\n\n  let data: any\n\n  try {\n    data = await response.json()\n  } catch {}\n\n  if (!response.ok) {\n    throw new Error(data.error?.message || 'Failed to test edge function', {\n      cause: { status: data.status },\n    })\n  }\n\n  return data as ResponseData\n}\n\ntype EdgeFunctionTestData = Awaited<ReturnType<typeof testEdgeFunction>>\n\nexport const useEdgeFunctionTestMutation = ({\n  onSuccess,\n  onError,\n  ...options\n}: Omit<\n  UseCustomMutationOptions<EdgeFunctionTestData, ResponseError, EdgeFunctionTestVariables>,\n  'mutationFn'\n> = {}) => {\n  return useMutation<EdgeFunctionTestData, ResponseError, EdgeFunctionTestVariables>({","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/supabase/supabase/blob/beee91b9c2228dd57302dec75c733baaa84ab543/apps/studio/data/edge-functions/edge-function-test-mutation.ts#L19-L55","documentation":"Fallback thrown by testEdgeFunction when the test endpoint returns non-2xx and the body either fails to parse as JSON (caught silently, `data` stays undefined) or lacks `error.message`. The thrown Error carries `cause: { status: data.status }` so callers can read the upstream HTTP status even though the message is generic.","triggerScenarios":"POSTing to the edge-function test proxy returns non-ok. If the body parsed, `data.error?.message` is shown; otherwise the generic 'Failed to test edge function' fires. Empty/non-JSON bodies land here.","commonSituations":"Edge function URL/method/headers invalid; function returns 5xx and the proxy surfaces no structured error; CORS or auth cookie missing; the function timed out and the gateway returned an HTML error page.","solutions":["Inspect `error.cause.status` in the catch — it carries the upstream status code.","Open the Network tab and read the raw response body for the true error text.","Confirm the function is deployed and the URL/method in the test panel match the function signature.","Check that authentication headers / API gateway JWT are attached if the function requires them."],"exampleFix":"// before\ntry { await testEdgeFunction(vars) } catch (e) { toast.error(String(e)) }\n// after — surface the upstream status\ntry { await testEdgeFunction(vars) }\ncatch (e) {\n  const status = (e as Error & { cause?: { status?: number } }).cause?.status\n  toast.error(status ? `Edge function test failed (HTTP ${status})` : 'Edge function test failed')\n}","handlingStrategy":"try-catch","validationCode":"// Validate request shape before calling the proxy\nfunction validateTestInput({ url, method }: { url: string; method: string }) {\n  try { new URL(url) } catch { throw new Error('Provide a valid absolute URL for the function') }\n  if (!['GET','POST','PUT','PATCH','DELETE','HEAD','OPTIONS'].includes(method.toUpperCase())) throw new Error('Unsupported HTTP method')\n}","typeGuard":"function hasEdgeError(x: unknown): x is { error: { message: string }; status?: number } {\n  return typeof x === 'object' && x !== null && typeof (x as any).error?.message === 'string'\n}","tryCatchPattern":"try { await testEdgeFunction(vars) }\ncatch (e) {\n  const status = (e as Error & { cause?: { status?: number } }).cause?.status\n  toast.error(status ? `Edge function test failed (HTTP ${status})` : 'Edge function test failed')\n}","preventionTips":["Validate the URL/method in the test panel before submit.","Read `error.cause.status` in the catch for actionable upstream detail.","Confirm the function is deployed and the auth context is present."],"tags":["edge-functions","api","network"],"backgroundTag":null,"analyzedSha":"beee91b9c2228dd57302dec75c733baaa84ab543","analyzedAt":"2026-08-12T06:51:48.935Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}