Skip to content

[Docs] incorrect example code in docs #8321

@tenkirin

Description

@tenkirin

Affected URL

https://nodejs.org/en/learn/getting-started/fetch#customizing-the-fetch-api-with-undici

Describe the issue in detail:

It is important to always either consume or cancel the response body anyway, but it isn't correctly handled in the example code, which may mislead new learners:

  const { statusCode, body } = await ollamaPool.request({
    path: '/api/generate',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ prompt, model: 'mistral' }),
  });
  // You can read about HTTP status codes here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
  // 200 means the request was successful.
  if (statusCode !== 200) {
    throw new Error(`Ollama request failed with status ${statusCode}`);
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    contentIssues/pr concerning contentlearnIssues/pr concerning the learn section

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions