{"record":{"id":"ee0224a4f4d8a584","repo":"hcengineering/platform","slug":"err-message-ee0224","errorCode":null,"errorMessage":"err.message","messagePattern":"err\\.message","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"services/gmail/pod-gmail/src/main.ts","lineNumber":199,"sourceCode":"            res.status(401).send()\n            return\n          }\n\n          const { workspace } = decodeToken(token)\n          const socialId = req.query.socialId as PersonId | undefined\n          if (socialId == null || socialId === '') {\n            res.status(400).send({ error: 'Missing socialId param' })\n            return\n          }\n          const state = await gmailController.getState(workspace, socialId)\n          if (state === undefined) {\n            res.status(404).send({ error: 'No gmail clients found for social id' })\n            return\n          }\n          res.send(state)\n        } catch (err: any) {\n          ctx.error('Failed to get integration state', { message: err.message })\n          res.status(500).send({ error: err.message })\n        }\n      }\n    },\n    {\n      endpoint: '/start-sync',\n      type: 'post',\n      handler: async (req, res) => {\n        try {\n          const token = extractToken(req.headers)\n\n          if (token === undefined) {\n            res.status(401).send()\n            return\n          }\n\n          const { workspace } = decodeToken(token)\n          const socialId = req.query.socialId as PersonId | undefined\n          ctx.info('Sync request received', { workspace, socialId })","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/services/gmail/pod-gmail/src/main.ts#L181-L217","documentation":"A 500 response whose body echoes err.message from the catch block of the integration-state GET handler. Any exception thrown by getState (DB errors, downstream service failures, bad auth) surfaces here as a generic 500.","triggerScenarios":"getState throws — e.g. database unreachable, storage/dal exceptions, or unexpected undefined fields — while handling GET /integration-state.","commonSituations":"Database outages or migrations, network partitions to storage, TypeError inside the controller when partial state exists, auth token decode errors bubbling up.","solutions":["Check the service logs for the 'Failed to get integration state' ctx.error entry to see the underlying cause","Verify the database/storage backing gmailController is reachable and migrated","Confirm the auth token is valid — decodeToken may throw before state lookup","Add more specific error handling for known failure modes instead of blindly returning err.message"],"exampleFix":"// before\n} catch (err: any) {\n  res.status(500).send({ error: err.message })\n}\n// after\n} catch (err: any) {\n  ctx.error('Failed to get integration state', { message: err.message })\n  res.status(500).send({ error: 'Internal error retrieving integration state' })\n}","handlingStrategy":"try-catch","validationCode":"// verify preconditions before calling\nif (!workspace || !socialId) throw new Error('workspace and socialId required')","typeGuard":"function isErrorResponse(res: Response): res is Response & { ok: false } {\n  return !res.ok\n}","tryCatchPattern":"try {\n  const res = await fetch(url)\n  if (!res.ok) {\n    const body = await res.json()\n    throw new Error(`integration-state 500: ${body.error ?? 'unknown'}`)\n  }\n  return await res.json()\n} catch (e) {\n  // retry with backoff; 500 may be transient storage failure\n}","preventionTips":["Retry 500s with exponential backoff since many are transient storage issues","Monitor server logs for 'Failed to get integration state' to catch systemic causes","Keep the storage layer backing gmailController healthy and migrated"],"tags":["http-500","gmail","unhandled-exception","rest-api"],"backgroundTag":"internal-server-error","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}