Hattrick

AI-powered code analysis and research for engineers who want to understand their code, not just change it.

Bring a question or a piece of code. Hattrick investigates the techniques, explains what holds up, and identifies changes worth considering.

The answer first. The evidence right behind it.

Browse research samples

Hat Trick research

Web platform · 326 characters

Research complete

Question

Is this the most modern way to handle fetch timeouts and cancellation in TypeScript?

Submitted code · fetch-json-timeout.tsTypeScript
export async function fetchJson(url: string, timeoutMs = 5000) {
  const controller = new AbortController()
  const timer = setTimeout(() => controller.abort(), timeoutMs)
  try {
    const response = await fetch(url, { signal: controller.signal })
    return await response.json()
  } finally {
    clearTimeout(timer)
  }
}

Result

TypeScript3 priority findings4 displayed sources

Modern foundation, incomplete failure contract

The cancellation primitive is current, but the helper leaves important failure behavior implicit. Keep AbortController, then make HTTP errors and timeout semantics explicit.

Priority findings

03
  1. 01

    AbortController is still the right foundation

    Keep

    Passing an AbortSignal to fetch remains the current web-platform pattern for cooperative cancellation.

    S1 · S5
  2. 02

    Check the HTTP result before parsing JSON

    Fix next

    Fetch resolves for HTTP error statuses. Check response.ok or response.status before treating the body as successful.

    S2 · S4
  3. 03

    Give callers a clear cancellation contract

    Decide

    The helper cannot distinguish its own timeout from caller-initiated cancellation. Add the distinction when callers need it.

    S1 · S5

Anatomy of a research report

Reports are organized around your question. Code reviews assess the techniques you use; broader questions get a structure that fits the investigation.

Verdict first
Start with the overall judgment, then scroll down for the details behind it.
Sources you can check
Follow the references to inspect the evidence and explore a finding further.
What to keep or change
See which techniques still hold up and where a change could help. Modern does not always mean better for your case.
Examples where useful
Code examples help explain non-obvious changes. Review and test them in your own system.

How it works

  1. 01

    Show Hattrick your code

    Paste code or ask an engineering question. Include what you want to understand, improve, or check.

  2. 02

    Hattrick investigates

    It looks for relevant documentation, research, and examples to assess the techniques in your code.

  3. 03

    Make an informed decision

    Read the verdict, then explore the findings and sources. You decide which changes belong in your code.

Analysis modes

Hat Trick

A source-backed report on your code or engineering question.

Hat Trick XX

A deeper review with more research and cross-checking. It takes longer and uses more of your allowance.

Limits & recommended usage

Code paste
1,000,000 characters
Focused review
10,000 or 22,000 characters
Chat message
8,000 characters
  • Start with the code relevant to your question. Add context about how it is used.
  • Choose Hat Trick for a regular report, or Hat Trick XX for a deeper investigation.
  • Create an account for one free Hat Trick report. Ongoing team access is available through the pilot.

Try Hattrick with your team

The team pilot includes 10 seats for $500 a month. We agree on usage limits and pilot terms with you before payment.

View pilot pricing