better error handling in js