Volnick
Volnick

Reputation: 89

Correct way of sending error information, but code still runs

What is the right way to send error information to my backend. I have the following example in my head.

The code is running, but at somepoint a value is broken. At this point I want to throw some error information to my backend and my application shouldn't stop. It would send me the error and continue.

Upvotes: 0

Views: 54

Answers (1)

IAmQuirkee
IAmQuirkee

Reputation: 132

Don't think you should have code that breaks in production, but you can do a try catch block.

function exampleFunction() {
    try {
        untestedFunction();
    } catch(err) {
        sendErrorToBackend(err)
    }
}

If the untestedFunction() breaks, it'll end up calling sendErrorToBackend which you could use to send the error log to your server.

Upvotes: 1

Related Questions