Add onError funct