Commit 3f71b927 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

proper error messages in query editor frontend

parent 2bf04824
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -1494,6 +1494,18 @@ ul.ui_tabs li.active a{
  outline: none;
}

#query_editor_error {
  display: none;
  padding: 7px;
  font-family: monospace;
  background: #ecc;
  border: 1px solid #f88;
}

#query_editor_error.visible {
  display:block;
}

.swatch {
  width: 10px;
  height: 10px;
+15 −1
Original line number Diff line number Diff line
@@ -7,12 +7,25 @@ FnordMetric = (function() {
    }

    var query = editor.getValue();
    if (query.length == 0) {
      return;
    }

    var xmlHttp = null;
    xmlHttp = new XMLHttpRequest();
    xmlHttp.open("POST", "/query", false);
    xmlHttp.send(query);

    console.log(xmlHttp.responseText);
    var response = JSON.parse(xmlHttp.responseText);

    var error_div = document.getElementById("query_editor_error");
    if (response.status == "success") {
      error_div.className = "";
    } else {
      error_div.className = "visible";
      error_div.innerHTML = response.error;
    }
  };

  var renderQueryView = function() {
@@ -26,7 +39,8 @@ FnordMetric = (function() {
        navbar +
        "<div id='query_editor'>" +
          "<textarea id='query_editor_textarea'></textarea>" +
        "</div>";
        "</div>" +
        "<div id='query_editor_error'></div>";

    editor = CodeMirror.fromTextArea(
        document.getElementById("query_editor_textarea"),
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ set(FNORDMETRIC_SOURCES
    stage/src/fnordmetric/util/format.cc
    stage/src/fnordmetric/util/inputstream.cc
    stage/src/fnordmetric/util/outputstream.cc
    stage/src/fnordmetric/util/jsonoutputstream.cc
    stage/src/fnordmetric/util/threadpool.cc
    stage/src/fnordmetric/util/runtimeexception.cc)

+4 −0
Original line number Diff line number Diff line
@@ -51,6 +51,10 @@ void HTTPMessage::addBody(const std::string& body) {
  addHeader("Content-Length", std::to_string(body_.size()));
}

void HTTPMessage::clearBody() {
  body_.clear();
}

std::unique_ptr<util::InputStream> HTTPMessage::getBodyInputStream() const {
  return util::StringInputStream::fromString(body_);
}
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ public:

  const std::string& getBody() const;
  void addBody(const std::string& body);
  void clearBody();

  std::unique_ptr<util::InputStream> getBodyInputStream() const;
  std::unique_ptr<util::OutputStream> getBodyOutputStream();
Loading