{"record":{"id":"7c560184d9038f9e","repo":"hoppscotch/hoppscotch","slug":"team-request-added-error-json-stringify-result","errorCode":null,"errorMessage":"Team Request Added Error: ${JSON.stringify(result.left)}","messagePattern":"Team Request Added Error: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/hoppscotch-common/src/services/team-collection.service.ts","lineNumber":778,"sourceCode":"      if (E.isLeft(result))\n        throw new Error(\n          `Team Collection Removed Error: ${JSON.stringify(result.left)}`\n        )\n\n      this.removeCollection(result.right.teamCollectionRemoved)\n    })\n\n    const [teamReqAdded$, teamReqAddedSub] = runGQLSubscription({\n      query: TeamRequestAddedDocument,\n      variables: {\n        teamID: this.teamID,\n      },\n    })\n\n    this.teamRequestAddedSub = teamReqAddedSub\n    this.teamRequestAdded$ = teamReqAdded$.subscribe((result: any) => {\n      if (E.isLeft(result))\n        throw new Error(\n          `Team Request Added Error: ${JSON.stringify(result.left)}`\n        )\n\n      this.addRequest({\n        id: result.right.teamRequestAdded.id,\n        collectionID: result.right.teamRequestAdded.collectionID,\n        request: translateToNewRequest(\n          JSON.parse(result.right.teamRequestAdded.request)\n        ),\n        title: result.right.teamRequestAdded.title,\n      })\n    })\n\n    const [teamReqUpdated$, teamReqUpdatedSub] = runGQLSubscription({\n      query: TeamRequestUpdatedDocument,\n      variables: {\n        teamID: this.teamID,\n      },","sourceCodeStart":760,"sourceCodeEnd":796,"githubUrl":"https://github.com/hoppscotch/hoppscotch/blob/1acb8a3a7581e4db32ba0d529170c4669a2e1053/packages/hoppscotch-common/src/services/team-collection.service.ts#L760-L796","documentation":"Thrown inside the TeamRequestAdded GraphQL subscription callback in registerSubscriptions() when the subscription delivers a Left result. This callback handles real-time 'request added' events, parsing the request JSON via translateToNewRequest. The throw-in-next pattern risks crashing the chain, and a throw before JSON.parse would mask the subscription error as a parse error.","triggerScenarios":"The TeamRequestAdded subscription emits an error result — WebSocket drop, backend GraphQL error, auth expiry, or invalid teamID. A separate risk: if result.right.teamRequestAdded.request is malformed JSON, JSON.parse would throw a SyntaxError (not this error), but the Left-check throw fires first when the result is an error.","commonSituations":"Network interruption; auth token expired; backend restart; team access changed; concurrent add event with unexpected payload shape.","solutions":["Replace the throw-in-next with a subscribe error callback.","Wrap JSON.parse and translateToNewRequest in a try-catch to handle malformed request payloads separately.","Re-register subscriptions on transient errors.","Log result.left for diagnosis."],"exampleFix":"// before\nthis.teamRequestAdded$ = teamReqAdded$.subscribe((result: any) => {\n  if (E.isLeft(result))\n    throw new Error(`Team Request Added Error: ${JSON.stringify(result.left)}`)\n  this.addRequest({ ..., request: translateToNewRequest(JSON.parse(result.right.teamRequestAdded.request)), ... })\n})\n\n// after\nthis.teamRequestAdded$ = teamReqAdded$.subscribe({\n  next: (result: any) => {\n    if (E.isLeft(result)) {\n      console.error('TeamRequestAdded error:', result.left)\n      return\n    }\n    try {\n      this.addRequest({ ..., request: translateToNewRequest(JSON.parse(result.right.teamRequestAdded.request)), ... })\n    } catch (e) {\n      console.error('Failed to parse incoming team request:', e)\n    }\n  },\n  error: (err) => { console.error('TeamRequestAdded stream error:', err) },\n})","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"this.teamRequestAdded$ = teamReqAdded$.subscribe({\n  next: (result: any) => {\n    if (E.isLeft(result)) {\n      console.error('TeamRequestAdded error:', result.left)\n      return\n    }\n    try {\n      this.addRequest({\n        ...,\n        request: translateToNewRequest(JSON.parse(result.right.teamRequestAdded.request)),\n        ...,\n      })\n    } catch (e) { console.error('Failed to parse incoming team request:', e) }\n  },\n  error: (err) => { console.error('TeamRequestAdded stream error:', err) },\n})","preventionTips":["Never throw inside a .subscribe next-handler.","Wrap JSON.parse and translateToNewRequest in a try-catch to handle malformed request payloads.","Use { next, error } subscribe signature for stream error handling.","Reconnect on transient errors; re-authenticate on auth errors.","Unsubscribe all team subscriptions on team switch or logout."],"tags":["team-collections","graphql","subscription","websocket","reactive"],"backgroundTag":null,"analyzedSha":"1acb8a3a7581e4db32ba0d529170c4669a2e1053","analyzedAt":"2026-08-12T11:34:52.648Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}