API returns invalid json if SQL query fails
Describe the bug
If a FlowAPI get_query_result request successfully gets result-retrieval SQL from flowmachine, but an error occurs while executing the SQL query, the API will send a 200 response with incomplete content ('{"query_id":"<query_id>", "query_result":['), because the result-streaming begins before the query is actually executed. This results in the following misleading error in flowclient:
JSONDecodeError: Expecting value: line 1 column 65 (char 64)
Product
FlowAPI
Version
1.18.1
Expected behaviour
If the result-retrieval SQL fails to execute, the response code should indicate an error (probably 500).
Part of the issue is that we catch a bare exception, log it, and then carry on, where we should almost certainly re-raise or throw a new one.