handle errors passed to next