reactjs / reactjs/react.dev

handle errors

Open
#3,336 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
11.8k
Forks
7.9k
Avg merge
1d 11h
Merged PRs (30d)
11

Description

The React team believes that server-side errors should be handled in the second then argument. But if an error occurs (an error in our logic) in the first argument of then, it will not be caught. So you think that logic errors should be caught elsewhere (maybe Error Boundary)?
image

fetch('https://jsonplaceholder.typicode.com/todos/1')
  .then(response => response.json())
  .then(json => {
     console.log(json)
     throw new Error('myError') // <= Error here
  },  
    (error) => {
       console.log(error) // <= do not work
    }).catch(error => console.log(error)) // <=  work

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the fetch example in the issue and compare the second then argument with catch and React Error Boundaries. Confirm how errors thrown in the first callback propagate, then identify the relevant React documentation page and define the issue as resolved once the guidance clearly explains where each kind of error is handled.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.