Added handling of error event

Added fix