{"record":{"id":"775d155ee92be1ac","repo":"CherryHQ/cherry-studio","slug":"api-error-json-stringify-data-error","errorCode":null,"errorMessage":"API Error: ${JSON.stringify(data.error)}","messagePattern":"API Error: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/ai/mcp/servers/didiMcp.ts","lineNumber":466,"sourceCode":"    const url = `${this.baseUrl}?key=${this.apiKey}`\n\n    const response = await fetch(url, {\n      method: 'POST',\n      headers: {\n        'Content-Type': 'application/json'\n      },\n      body: JSON.stringify(requestData)\n    })\n\n    if (!response.ok) {\n      const errorText = await response.text()\n      throw new Error(`HTTP ${response.status}: ${errorText}`)\n    }\n\n    const data = await response.json()\n\n    if (data.error) {\n      throw new Error(`API Error: ${JSON.stringify(data.error)}`)\n    }\n\n    return data.result\n  }\n}\n\nexport default DiDiMcpServer\n","sourceCodeStart":448,"sourceCodeEnd":474,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/mcp/servers/didiMcp.ts#L448-L474","documentation":"Generic Error thrown by DiDiMcpServer.makeRequest when the upstream returns HTTP 200 but the JSON body contains a truthy 'error' field — a JSON-RPC level error from the DiDi gateway. This means the transport succeeded but the application-level request was rejected (e.g., invalid parameters, business-rule violation, insufficient permissions).","triggerScenarios":"The DiDi API responds with a 200 OK but the body is a JSON-RPC error object. Common with invalid method parameters, unsupported region, disabled service, or business-logic rejections (e.g., no drivers available, order already cancelled).","commonSituations":"Passing semantically invalid arguments that pass HTTP validation but fail business rules; calling a taxi method in an unsupported city; cancelling an order that is already completed; the API key lacks the required service scope.","solutions":["Inspect JSON.stringify(data.error) for the upstream error code and message.","Correct the request parameters based on the upstream error description.","Verify the API key has access to the requested service/method.","Handle known business-rule errors gracefully (e.g., no drivers available)."],"exampleFix":"// before\nif (data.error) {\n  throw new Error(`API Error: ${JSON.stringify(data.error)}`)\n}\n\n// after\nif (data.error) {\n  logger.warn('DiDi API business error', { code: data.error.code, message: data.error.message })\n  throw new Error(`API Error (${data.error.code}): ${data.error.message ?? JSON.stringify(data.error)}`)\n}","handlingStrategy":"try-catch","validationCode":"// Validate parameters match DiDi API business rules before calling\nif (method === 'taxi_create_order' && (!params.departure_latitude || !params.destination_latitude)) {\n  throw new Error('Departure and destination coordinates are required')\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await makeRequest(method, params)\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('API Error:')) {\n    const errorDetail = JSON.parse(e.message.replace('API Error: ', ''))\n    // handle known business errors (no drivers, order already cancelled, etc.)\n    if (errorDetail.code === 'NO_DRIVERS_AVAILABLE') {\n      return { content: [{ type: 'text', text: 'No drivers available in your area right now.' }] }\n    }\n  }\n  throw e\n}","preventionTips":["Inspect the upstream error code in data.error to handle business-rule rejections.","Validate semantic parameters (coordinates, order state) before calling.","Confirm the API key has the required service scope."],"tags":["network","didi","api-error","json-rpc"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}