handle errors before emitting new state