From 1760d927c8f45ce02b1068eacbc419501f5cb525 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Tue, 22 Jan 2013 01:50:16 +0100 Subject: [PATCH] Add error propagation to web UI via special JSON error type. --- rules/ast/printer.go | 4 ++-- static/js/rickshaw.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/rules/ast/printer.go b/rules/ast/printer.go index 17c17fcec..d39fcbe00 100644 --- a/rules/ast/printer.go +++ b/rules/ast/printer.go @@ -132,10 +132,10 @@ func (matrix Matrix) ToString() string { func ErrorToJSON(err error) string { errorStruct := struct { Type string - Error string + Value string }{ Type: "error", - Error: err.Error(), + Value: err.Error(), } errorJSON, err := json.MarshalIndent(errorStruct, "", "\t") diff --git a/static/js/rickshaw.js b/static/js/rickshaw.js index a2e286a6e..13b318dd7 100644 --- a/static/js/rickshaw.js +++ b/static/js/rickshaw.js @@ -84,6 +84,10 @@ function submitQuery() { dataType: "json", data: form.serialize(), success: function(json, textStatus) { + if (json.Type == "error") { + alert(json.Value); + return; + } data = transformData(json); if (data.length == 0) { alert("No datapoints found.");