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 {
errorStruct := struct {
Type string
Error string
Value string
}{
Type: "error",
Error: err.Error(),
Value: err.Error(),
}
errorJSON, err := json.MarshalIndent(errorStruct, "", "\t")

View File

@ -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.");