{"record":{"id":"1422b831ff91e8ec","repo":"twentyhq/twenty","slug":"server-error-response-status","errorCode":null,"errorMessage":"Server error (${response.status})","messagePattern":"Server error \\((.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-apps/internal/twenty-partners/src/modules/shared/front-components/call-app-route.ts","lineNumber":40,"sourceCode":"): Promise<unknown> => {\n  const token = process.env.TWENTY_APP_ACCESS_TOKEN;\n\n  const functionsUrl = process.env.TWENTY_FUNCTIONS_URL;\n  const apiUrl = process.env.TWENTY_API_URL ?? '';\n  const normalizedPath = path.startsWith('/') ? path : `/${path}`;\n  const url = functionsUrl ? `${functionsUrl}${normalizedPath}` : `${apiUrl}/s${normalizedPath}`;\n\n  const response = await fetch(url, {\n    method: 'POST',\n    headers: {\n      'Content-Type': 'application/json',\n      ...(token ? { Authorization: `Bearer ${token}` } : {}),\n    },\n    body: JSON.stringify(body),\n  });\n\n  if (!response.ok) {\n    throw new Error(await extractErrorMessage(response));\n  }\n\n  return response.json();\n};\n","sourceCodeStart":22,"sourceCodeEnd":45,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-apps/internal/twenty-partners/src/modules/shared/front-components/call-app-route.ts#L22-L45","documentation":"callAppRoute POSTs JSON to a Twenty app route (TWENTY_FUNCTIONS_URL or TWENTY_API_URL/s<path>) and, on a non-ok response, extracts a message. 'Server error (status)' is the FALLBACK string used only when the response body is not parseable JSON or the parsed JSON lacks any of messages/message/error. So this exact text means the server returned an error status with an unstructured (often non-JSON) body.","triggerScenarios":"response.ok is false AND extractErrorMessage could not find a structured error field. Happens when a gateway/proxy returns HTML (502/503/504), the app route threw an unhandled error producing a plain-text body, the URL is wrong (404 HTML page), or TWENTY_APP_ACCESS_TOKEN is missing/expired and the server returns a non-JSON auth error.","commonSituations":"TWENTY_FUNCTIONS_URL or TWENTY_API_URL misconfigured (trailing slash, wrong host) hitting a 404 HTML page; functions deployment down (502 from platform); token unset so auth middleware returns a non-JSON 401; app route not deployed/registered.","solutions":["Verify TWENTY_FUNCTIONS_URL / TWENTY_API_URL / TWENTY_APP_ACCESS_TOKEN are set and the URL resolves to the Twenty workspace.","Confirm the target app route is deployed and registered at the given path.","Reproduce the POST with curl -i to see the raw status and body (HTML vs JSON).","If the body is HTML from a gateway, check the functions/hosting platform health."],"exampleFix":"// before\nif (!response.ok) {\n  throw new Error(await extractErrorMessage(response));\n}\n\n// after — include the URL and status code in the fallback so the cause is diagnosable\nif (!response.ok) {\n  const message = await extractErrorMessage(response);\n  throw new Error(`${message} (url=${url}, status=${response.status})`);\n}","handlingStrategy":"try-catch","validationCode":"function assertCallAppRouteEnv() {\n  const functionsUrl = process.env.TWENTY_FUNCTIONS_URL;\n  const apiUrl = process.env.TWENTY_API_URL;\n  if (!functionsUrl && !apiUrl) {\n    throw new Error('Set TWENTY_FUNCTIONS_URL or TWENTY_API_URL before calling app routes');\n  }\n  if (!process.env.TWENTY_APP_ACCESS_TOKEN) {\n    throw new Error('Set TWENTY_APP_ACCESS_TOKEN before calling app routes');\n  }\n}\nawait assertCallAppRouteEnv();","typeGuard":null,"tryCatchPattern":"try {\n  return await callAppRoute('/my-route', body);\n} catch (err) {\n  // 'Server error (status)' means the body was non-JSON or lacked an error field.\n  // Reproduce with curl -i against the same URL/token to see the raw body.\n  throw new Error(`callAppRoute failed: ${err instanceof Error ? err.message : String(err)}`);\n}","preventionTips":["Always set TWENTY_FUNCTIONS_URL (or TWENTY_API_URL) and TWENTY_APP_ACCESS_TOKEN.","Confirm the app route is deployed and registered at the path before calling.","Reproduce failures with curl -i to inspect raw status/body (HTML vs JSON).","Treat a non-JSON error body as a gateway/deployment problem, not an app logic error."],"tags":["network","http","app-route","env","partners"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}