Add error propagation to web UI via special JSON error type.

This commit is contained in:
Julius Volz 2013-01-22 01:50:16 +01:00
parent 49c87348b5
commit 1760d927c8
2 changed files with 6 additions and 2 deletions

View file

@ -132,10 +132,10 @@ func (matrix Matrix) ToString() string {
func ErrorToJSON(err error) string { func ErrorToJSON(err error) string {
errorStruct := struct { errorStruct := struct {
Type string Type string
Error string Value string
}{ }{
Type: "error", Type: "error",
Error: err.Error(), Value: err.Error(),
} }
errorJSON, err := json.MarshalIndent(errorStruct, "", "\t") errorJSON, err := json.MarshalIndent(errorStruct, "", "\t")

View file

@ -84,6 +84,10 @@ function submitQuery() {
dataType: "json", dataType: "json",
data: form.serialize(), data: form.serialize(),
success: function(json, textStatus) { success: function(json, textStatus) {
if (json.Type == "error") {
alert(json.Value);
return;
}
data = transformData(json); data = transformData(json);
if (data.length == 0) { if (data.length == 0) {
alert("No datapoints found."); alert("No datapoints found.");