{"record":{"id":"0e381486f74b10bf","repo":"toeverything/AFFiNE","slug":"firsterror-message","errorCode":null,"errorMessage":"${firstError.message}","messagePattern":"\\$\\{firstError\\.message\\}","errorType":"exception","errorClass":"GraphQLError","httpStatus":null,"severity":"error","filePath":"packages/common/graphql/src/fetcher.ts","lineNumber":223,"sourceCode":"      headers['content-type'] = 'application/json';\n    }\n    const ret = fetcher(\n      endpoint,\n      merge(options.context, {\n        method: 'POST',\n        headers,\n        body: isFormData ? body : JSON.stringify(body),\n        timeout: options.timeout,\n        signal: options.signal,\n      })\n    ).then(async res => {\n      if (res.headers.get('content-type')?.startsWith('application/json')) {\n        const result = (await res.json()) as ExecutionResult;\n        if (res.status >= 400 || result.errors) {\n          if (result.errors && result.errors.length > 0) {\n            // throw the first error is enough\n            const firstError = result.errors[0];\n            throw new GraphQLError(firstError.message, firstError);\n          } else {\n            throw new GraphQLError('Empty GraphQL error body');\n          }\n        } else if (result.data) {\n          // we have to cast here because the type of result.data is a union type\n          return result.data as any;\n        }\n      }\n\n      throw new GraphQLError(\n        'GraphQL query responds unexpected result, query ' + options.query.op\n      );\n    });\n\n    return ret;\n  };\n\n  return gqlFetch;","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/common/graphql/src/fetcher.ts#L205-L241","documentation":"gqlFetch extracts result.errors from the GraphQL JSON response and throws a GraphQLError with the first error's message, surfacing server-side execution errors (auth failures, bad input) as exceptions on the client.","triggerScenarios":"Thrown at packages/common/graphql/src/fetcher.ts:223 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the underlying GraphQL error message included in the error to find the real cause.","Fix the failing field or permission issue reported by the first GraphQL error.","Retry the request after correcting the query or its variables."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}