You may be using fetch with async/await wrong...

preview_player
Показать описание

#javascript #js #webdev #typescript
Рекомендации по теме
Комментарии
Автор

I only catch errors so I can throw them myself.

alext
Автор

The cause field is intended to be used for rethrowing exceptions. It is the corrolary to an innerException in other languages. This is not a standard usage of the cause field.

KirkWaiblinger
Автор

The perfection is hard in this industry

davidrivers
Автор

This JavaScript videos that YouTube suggest always remind me of how helpful are static types and type-safety when developing reliable software.

karlosdaniel
Автор

i even go further and i pass all my requests thro request handling async functions to abstract out the error handling to a single function so i can just worry about fetching/posting/puting data

fueledbycoffee
Автор

Or you can use Axios and its interceptors, which you can do it globally on your app. Using interceptors, you can focus on creating async services as atomically as possible.

rafaelmramblas
Автор

Yeah, though for the sake of type safety you might want to create your custom error class, as the native one accepts only one parameter and it's a string message.

darekcybulski
Автор

this is the best solution actually. I used to use Axios, but now I prefer creating my own fetch wrappers. more control + smaller footprint = smaller bundle size

Dev-Siri
Автор

Started playing with wretch recently. Nice addi tion over fetch

nivoset
Автор

This is why I call database directly from frontend, which itself is a Sqlite that's deployed along with HTML and Javascript

FalconTheFries
Автор

You also forgot to parse/validate the user object into a known object structure!

ianliu
Автор

also we can use validators like `yup`... also we can use global handler for all rejections `addEventListener("unhandledrejection", (event) => {});`

AndrewFloatrx
Автор

use monads and functional async without even know these concepts. love "plan" in js-awe library.

josemarin
Автор

And if the response was text and not json?

ofeenee
Автор

You still need to check if user is an object and if the properties exist before accessing them

nowayicommented
Автор

that looks like acid to write and read

Kim-trop
Автор

Handling errors is a very important thing. My parents handled me for 20 years and I'm getting better

fromant
Автор

Great video. How did you make the subtitle like that?

reinhard_silaen
Автор

Great video. Btw I mostly used axios for real user apps mainly due to middlewares

How can you do middleware request like axios using fetch (autonatically adding auth headers and trying max 3 times if request fails) ?

Can you doa video on same?

shivamjhaa
Автор

can't you just check res.status directly ?? Sorry the noob question

anuradhaamarasinghe