BL-697: Handle JavaScript errors better