{"record":{"id":"976b6ac123d1320c","repo":"GrapesJS/grapesjs","slug":"await-response-text","errorCode":null,"errorMessage":"await response.text()","messagePattern":"await response\\.text\\(\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/data_sources/model/DataSource.ts","lineNumber":266,"sourceCode":"\n    if (!provider) return;\n\n    if (isString(provider)) {\n      // TODO: implement providers as plugins (later)\n      return;\n    }\n\n    const providerGet = isString(provider.get) ? { url: provider.get } : provider.get;\n    const { url, method, headers, body } = providerGet;\n\n    const fetchProvider = async () => {\n      const dataSource = this;\n\n      try {\n        em.trigger(em.DataSources.events.providerLoadBefore, { dataSource });\n\n        const response = await fetch(url, { method, headers, body });\n        if (!response.ok) throw new Error(await response.text());\n        const result: DataSourceProviderResult = await response.json();\n\n        if (result?.records) this.setRecords(result.records as any);\n        if (result?.schema) this.upSchema(result.schema);\n\n        em.trigger(em.DataSources.events.providerLoad, { result, dataSource });\n      } catch (error: any) {\n        em.logError(error.message);\n        em.trigger(em.DataSources.events.providerLoadError, { dataSource, error });\n      }\n    };\n\n    await fetchProvider();\n  }\n\n  /**\n   * Removes a record from the data source by its ID.\n   *","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/GrapesJS/grapesjs/blob/2bdeda85b82b8b9ceae42fd6558cbbcae5ec2d21/packages/core/src/data_sources/model/DataSource.ts#L248-L284","documentation":"When loading data from a remote provider (fetch), GrapesJS checks `response.ok`; if the HTTP status is not 2xx it throws an Error whose message is the raw response body text, so the surfaced message is whatever the server returned (e.g. 'await response.text()' content shown here is the body).","triggerScenarios":"`dataSource.load()` / `fetchProvider` hitting a URL that returns 401/403/404/500, CORS failures producing error statuses, wrong `url`/`method`/`headers`/`body` in the provider config, or server returning non-JSON errors.","commonSituations":"Expired auth tokens on a REST endpoint, misconfigured provider URL in the Data Sources config, server downtime, or a proxy returning an HTML error page.","solutions":["Inspect the thrown message (server response body) and fix the underlying HTTP problem (URL, auth headers, method, body).","Verify the endpoint returns 2xx with JSON of shape `{ records: [...], schema: [...] }`.","Check CORS and credentials if the fetch is cross-origin; wrap `dataSource.load()` in try/catch and retry or show a UI error.","Test the URL with curl/fetch outside GrapesJS to confirm the API works."],"exampleFix":"// before\nawait dataSource.load(); // throws with server body text on 401\n// after\ntry {\n  await dataSource.load();\n} catch (err) {\n  console.error('Provider load failed:', err.message); // inspect server response\n  // fix url/headers, then retry\n}","handlingStrategy":"retry","validationCode":"const res = await fetch(url, { method, headers, body });\nif (!res.ok) throw new Error(`Provider endpoint unhealthy: ${res.status}`);\n// only then call dataSource.load()","typeGuard":"null","tryCatchPattern":"try {\n  await dataSource.load();\n} catch (err) {\n  console.error('Data provider load failed:', err.message); // err.message = server body\n  // fix url/headers based on message, or retry with backoff\n}","preventionTips":["Validate provider url/method/headers/body config before load","Check auth token expiry and CORS for remote providers","Monitor the endpoint's contract: it must return JSON { records, schema } with 2xx","Add retry/backoff around dataSource.load()"],"tags":["network","fetch","http-error","data-sources"],"backgroundTag":"http-request-failed","analyzedSha":"2bdeda85b82b8b9ceae42fd6558cbbcae5ec2d21","analyzedAt":"2026-08-30T11:47:52.267Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}