fix error handling after query