JavaScript Node.js Basics Handling Errors in Node Handling Status Code Errors

Aakash Srivastava
Aakash Srivastava
5,413 Points

Handling Status Codes Error

In the previous video , Chalkley included the try catch statement inside the response.on('end', () => {......} block in case case user enters the wrong profile name or profile doesn't exist , it will handle the error.
Now , when he put the condition i,e if (response.statusCode === 200) to handle the same error i,e if profile not found , is it still necessary to write that try catch statement written inside the block `response.on('end', () => {......} .
I think , try catch doesn't do anything now as , if profile will not be found , that if else statement will handle those before it will reach to the try catch
May be i am getting wrong . Need help

1 Answer

<noob />
<noob />
16,621 Points

He wasn't handilng profile not foudn error, he is handling what happend if u get a different response.statusCode rather than 200.