Better Error Handling in JavaScript / Typescript