BL-697: Improve handling of JavaScript errors