Corrected handling when query returns error message