handle error event properly