From the course: Angular: Testing and Debugging

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Catching errors from an observable

Catching errors from an observable - Angular Tutorial

From the course: Angular: Testing and Debugging

Start my 1-month free trial

Catching errors from an observable

- [Instructor] Misspelled resource locators are a common error when working with asynchronous server requests. To mimic this issue, let's intentionally add a typo to the end of the URL in the Git Remote method in our web storage service. So, instead of requesting data from /mock/api/filter we're going to request it from /mock/api/filter/foo Back in the browser, we see a console message telling us that the git request for the specified URL returns a 404 Not Found error. There's also this generic error object returned from Angular's ErrorHandler that has more information about our server request. It's good practice to always catch server errors and there are many ways to do so at both the component level and the service level. For this course, we'll keep things simple and update the subscribe method in the ngOnInitError method in our component with a second argument. This argument is a callback that's invoked only when an error is returned from an observable. The callback takes a single…

Contents