I have a pure function that looks like :
function foobar(str) {
let newStr;
// code that depends on str and forge a new string
...
return newStr;
}
Now, I would like to raise an error if str
is not as expected.
My error will be a simple object like { code: 'foo', msg: 'bar' } and I'm searching for the proper way to return this error from my function.
I'd like to avoid exceptions and promises (as they are asynchronous) and ideally, I'd like this function to adopt a functional programming style.
Any clue?