add err handling in js