From the course: Learning Node.js
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Solution: Convert for error handling - Node.js Tutorial
From the course: Learning Node.js
Solution: Convert for error handling
(upbeat music) - [Instructor] For this solution, I converted my function to an async function, and then I wrapped our request in a try block. I then save the result from the request using a weight, into a variable called result. And then I simply console log the results, which replicates the same behavior we have up top. And now in case there is an error, I use catch, to get the error, and then console log that error. And so these two functions should have the same behavior, in that the error is displayed if there is an error. But the result is always displayed unless there is an error.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.