correctly handle error callback (fix #614)