Skip to content
Snippets Groups Projects
Commit ba070a07 authored by Cam Saul's avatar Cam Saul
Browse files

Structured QP now returns useful error responses

parent dea93ca6
No related branches found
No related tags found
No related merge requests found
......@@ -47,10 +47,16 @@
{:pre [(integer? (:database query)) ; double check that the query being passed is valid
(map? (:query query))
(= (name (:type query)) "query")]}
(->> (process query)
eval
(post-process query)
(annotate/annotate query)))
(try
(->> (process query)
eval
(post-process query)
(annotate/annotate query))
(catch java.sql.SQLException e
{:status :failed
:error (->> (.getMessage e) ; error message comes back like "Error message ... [status-code]
(re-find #"(?s)(^.*)\s+\[[\d-]+\]$") ; status code isn't useful and makes unit tests hard to write so strip it off
second)}))) ; (?s) = Pattern.DOTALL - tell regex `.` to match newline characters as well
(defn process-and-run
......
......@@ -436,3 +436,18 @@
;; Rows come back like `[value timestamp]` but it is hard to compare timestamps directly since the values that come back are casted
;; to Dates and the exact value depends on the locale of the machine running the tests. So just drop the timestamps from the results.
(update-in [:data :rows] (partial map first))))
;; # ERROR RESPONSES
;; Check that we get an error response formatted the way we'd expect
(expect
{:status :failed
:error "Column \"CHECKINS.NAME\" not found; SQL statement:\nSELECT \"CHECKINS\".* FROM \"CHECKINS\" WHERE (\"CHECKINS\".\"NAME\" = ?)"}
(process-and-run {:database @db-id
:type :query
:query {:source_table (table->id :checkins)
:filter ["=" (field->id :venues :name) 1] ; wrong Field
:aggregation ["rows"]
:breakout [nil]
:limit nil}}))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment