Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback for “Error Handling” #562

Open
quul opened this issue Jan 26, 2024 · 0 comments
Open

Feedback for “Error Handling” #562

quul opened this issue Jan 26, 2024 · 0 comments

Comments

@quul
Copy link

quul commented Jan 26, 2024

It seemed that these piece of error handling code could never pass typescript type check as my littele knowledge of typescript.
I know this is just for javascript, but since swr is friendly to typescript, maybe it's better to make a Typescript demo?

if (!res.ok) {
const error = new Error('An error occurred while fetching the data.')
// Attach extra info to the error object.
error.info = await res.json()
error.status = res.status
throw error
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant