270. Using the catchError Operator
Jul 21, 2026 06:05
· 2:13
· English
· Whisper Turbo
· 2 ஒலிப்பேழைகள்
இந்த நகல் காலாவதியாகும் 7 நாட்கள்.
நிலையான சேமிப்புக்காக மேம்படுத்தல் →
காட்டு
0:02
S…
Speaker 2 (270. Using the catchError Operator)
No matter how you handle your error,
0:04
S…
Speaker 2 (270. Using the catchError Operator)
what can be useful is a special operator that can
0:08
S…
Speaker 2 (270. Using the catchError Operator)
assist you with handling errors.
0:10
S…
Speaker 2 (270. Using the catchError Operator)
And that special operator needs to be imported from rxjs
0:14
S…
Speaker 2 (270. Using the catchError Operator)
operators and it's named catch error and it does exactly what the
0:18
S…
Speaker 2 (270. Using the catchError Operator)
name suggests.
0:19
S…
Speaker 2 (270. Using the catchError Operator)
Now let's say here,
0:21
S…
Speaker 2 (270. Using the catchError Operator)
when we fetch posts where we already pipe some data,
0:25
S…
Speaker 2 (270. Using the catchError Operator)
we got an error and we want to handle
0:29
S…
Speaker 1 (270. Using the catchError Operator)
that.
0:30
S…
Speaker 2 (270. Using the catchError Operator)
Now we can simply add the catch error operator here.
0:34
S…
Speaker 2 (270. Using the catchError Operator)
We get our error response in here.
0:36
S…
Speaker 2 (270. Using the catchError Operator)
So we get exactly the same data we would get
0:40
S…
Speaker 2 (270. Using the catchError Operator)
in that second argument of the subscribe method.
0:45
S…
Speaker 2 (270. Using the catchError Operator)
And in here,
0:46
S…
Speaker 2 (270. Using the catchError Operator)
you could now do stuff like send to analytics server
0:50
S…
Speaker 2 (270. Using the catchError Operator)
or anything like that.
0:51
S…
Speaker 2 (270. Using the catchError Operator)
So some generic error handling task you might wanna do.
0:54
S…
Speaker 2 (270. Using the catchError Operator)
Maybe not related to the UI.
0:57
S…
Speaker 2 (270. Using the catchError Operator)
Though of course you could use the subject and next the error message
1:01
S…
Speaker 1 (270. Using the catchError Operator)
here too.
1:01
S…
Speaker 2 (270. Using the catchError Operator)
But maybe you have some behind the scenes stuff you want to do when an error occurs.
1:06
S…
Speaker 2 (270. Using the catchError Operator)
Log it somewhere,
1:07
S…
Speaker 2 (270. Using the catchError Operator)
send it to your own server,
1:08
S…
Speaker 2 (270. Using the catchError Operator)
your analytics server,
1:10
S…
Speaker 2 (270. Using the catchError Operator)
anything like that.
1:11
S…
Speaker 2 (270. Using the catchError Operator)
And once you're done handling that error,
1:13
S…
Speaker 2 (270. Using the catchError Operator)
you should pass it on though.
1:15
S…
Speaker 2 (270. Using the catchError Operator)
It definitely needs to be able to reach subscribe.
1:18
S…
Speaker 2 (270. Using the catchError Operator)
Just as you need to pass something here in map as well.
1:21
S…
Speaker 2 (270. Using the catchError Operator)
So we also now need to create a new
1:25
S…
Speaker 2 (270. Using the catchError Operator)
observable that wraps that error.
1:27
S…
Speaker 2 (270. Using the catchError Operator)
And for that,
1:28
S…
Speaker 2 (270. Using the catchError Operator)
you can import something from RxJS and that something is throw
1:33
S…
Speaker 1 (270. Using the catchError Operator)
error.
1:33
S…
Speaker 2 (270. Using the catchError Operator)
And that is a function that will yield a new observable and
1:37
S…
Speaker 2 (270. Using the catchError Operator)
it yields a new observable by wrapping an error.
1:41
S…
Speaker 2 (270. Using the catchError Operator)
So here we can now throw the...
1:45
S…
Speaker 2 (270. Using the catchError Operator)
Error response,
1:46
S…
Speaker 2 (270. Using the catchError Operator)
you could also throw a new custom error which you generated whatever
1:50
S…
Speaker 1 (270. Using the catchError Operator)
you want.
1:52
S…
Speaker 1 (270. Using the catchError Operator)
Important,
1:53
S…
Speaker 2 (270. Using the catchError Operator)
you need to return that observable which is created by throw
1:57
S…
Speaker 1 (270. Using the catchError Operator)
error.
1:57
S…
Speaker 2 (270. Using the catchError Operator)
And now with that,
1:59
S…
Speaker 2 (270. Using the catchError Operator)
this of course doesn't do anything useful here,
2:01
S…
Speaker 2 (270. Using the catchError Operator)
but it's just an idea that you could consider using catch
2:06
S…
Speaker 2 (270. Using the catchError Operator)
error if you have some generic error handling task you also
2:10
S…
Speaker 2 (270. Using the catchError Operator)
wanna execute.
இந்த ஒலிப்பதிவு AI (தானியங்கி பேச்சு அடையாளம்) மூலம் உருவாக்கப்பட்டது. பிழைகள் இருக்கலாம் - முக்கியமான பயன்பாட்டுக்கு மூல ஒலியை சரிபார்க்கவும். AI கொள்கை
சுருக்கம்
இந்த நகலெடுப்புக்கான AI சுருக்கத்தை உருவாக்க சுருக்கம் என்பதை க்ளிக் செய்யவும்.
சுருக்கப்படுகிறது...
இந்த நகலை AI க்குக் கேட்கவும்
இந்த நூலைப் பற்றி ஏதாவது கேட்கவும் - AI தொடர்புடைய பகுதிகளைக் கண்டுபிடித்து பதிலளிக்கும்.