Is there a way in Javascript to trigger a method when there is an error in the console?

I want to show a textbox on screen when there is an error in the API and `jquery` gives an automated message in the console for this.

I don't need to fetch the message, I just want to know when there is an error in the console.