Search code examples
javascriptc#reactjsasp-net-core-spa-servicesdotnet-new

Javascript errors shown as a fullpage on Visual Studio. How to disable?


So I am into React just lately and trying it on visual studio with a React app and C#. But it is a bit annoying that Javascript errors are shown as a full page instead of showing it on console.

Is there any way to disable this? I couldn't find a way of my own on and google did not help as it does not shows what I want

Image that shows runtime error

If this is duplicate, it woudl also help.

I am trying to have disabled Visual Studio runtime errors as full page instead of console. I tried looking into Visual Studio, but I did not find anything and google it does not show that I am looking for.


Solution

  • The problem you are facing isn't caused by VS Code, but by react itself
    It isn't even a problem, it is just a way to let you know there is a problem with your code.

    What you need to work on is your error handling to prevent your application from crashing as experienced by yourself.
    Try making use of try and catch or .then().catch() for the block of code causing the error.

    try {
        // Your code here
    } catch (error) {
        // If an error occurs
        console.log(error); // shows the error in your console as message
        console.error(error); // shows the error in your console as an error
        alert(error);
        return error;
    
        // You can do whatever you want with the error here
    }
    
    doSomething()
    .then(res => console.log(res))
    .catch(error => {
        // If an error occurs
        console.log(error); // shows the error in your console as message
        console.error(error); // shows the error in your console as an error
        alert(error);
        return error;
    
        // You can do whatever you want with the error here
    })