{"record":{"id":"4e3cdf5402c96ab3","repo":"payloadcms/payload","slug":"network-response-was-not-ok","errorCode":null,"errorMessage":"Network response was not ok","messagePattern":"Network response was not ok","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/payload/src/fields/validations.ts","lineNumber":350,"sourceCode":"    if (Array.isArray(value) && value.length === 0) {\n      return false\n    }\n\n    if (typeof value === 'object' && Object.keys(value).length === 0) {\n      return false\n    }\n\n    return true\n  }\n\n  const fetchSchema = ({ schema, uri }: { schema: JSONSchema4; uri: string }) => {\n    if (uri && schema) {\n      return schema\n    }\n    return fetch(uri)\n      .then((response) => {\n        if (!response.ok) {\n          throw new Error('Network response was not ok')\n        }\n        return response.json()\n      })\n      .then((_json) => {\n        const json = _json as {\n          id: string\n        }\n        const jsonSchemaSanitizations = {\n          id: undefined,\n          $id: json.id,\n          $schema: 'http://json-schema.org/draft-07/schema#',\n        }\n\n        return Object.assign(json, jsonSchemaSanitizations)\n      })\n  }\n\n  if (required && !value) {","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/fields/validations.ts#L332-L368","documentation":"The JSON field's validator fetches a remote JSON Schema (via the field's `jsonSchema.uri`) and the HTTP response status was not ok (`!response.ok`, i.e. non-2xx). The fetch runs as part of validating submitted JSON against the schema, so a transport/HTTP failure surfaces as this generic `Error`.","triggerScenarios":"A `json` field configured with `{ jsonSchema: { uri: 'https://example.com/schema.json' } }` where the URL returns 404, 500, requires auth, or is unreachable; the host is down; CORS blocks the request from the browser/runtime.","commonSituations":"External schema URL moved or changed scheme; firewall/proxy blocking outbound requests in the deployment environment; schema endpoint temporarily 5xx; running validations in a sandboxed/edge runtime without network access.","solutions":["Verify the `uri` is reachable from the server (curl it) and returns 2xx with valid JSON.","Inline the schema using `jsonSchema: { schema: {...} }` to remove the network dependency.","Host the schema on a stable, same-origin endpoint and ensure it allows the relevant origin/headers.","Catch fetch failures and provide a fallback, or skip remote schema validation in low-trust environments."],"exampleFix":"// before\n{ name: 'config', type: 'json', jsonSchema: { uri: 'https://old.example.com/schema.json' } }\n// after (inline schema, no network)\n{ name: 'config', type: 'json', jsonSchema: { schema: myJsonSchemaObject } }","handlingStrategy":"retry","validationCode":"// before persisting, confirm the remote schema is reachable and 2xx\nasync function schemaUriOk(uri) {\n  try {\n    const res = await fetch(uri, { method: 'GET' })\n    return res.ok\n  } catch { return false }\n}\nif (!await schemaUriOk(field.jsonSchema.uri)) {\n  // fall back to inline schema or skip remote validation\n}","typeGuard":"function isJsonFieldWithRemoteSchema(f: any): f is { type: 'json'; jsonSchema: { uri: string } } {\n  return f?.type === 'json' && typeof f?.jsonSchema?.uri === 'string' && !f.jsonSchema.schema\n}","tryCatchPattern":"// the validator is internal; wrap the create/update call\ntry {\n  await payload.create({ collection: 'things', data })\n} catch (err) {\n  if (/Network response was not ok/i.test(err?.message ?? '')) {\n    // likely the json schema fetch failed; retry with backoff or fall back to inline schema\n  } else throw err\n}","preventionTips":["Prefer inline `jsonSchema: { schema: {...} }` over remote `uri` to remove network dependency.","Host schemas on a stable same-origin endpoint with monitoring.","Ensure the runtime (node/edge) permits outbound requests to the schema host."],"tags":["json","json-schema","network","fetch","validation","runtime"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}