added begin rescue to gateway code