<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -65,6 +65,7 @@ Here's plotting stuff.&lt;br \&gt;
 &lt;/table&gt;
 &lt;/form&gt;
 
+&lt;div id=&quot;errormsg&quot;&gt;&lt;/div&gt;
 &lt;div id=&quot;graph&quot;&gt;&lt;/div&gt;
 &lt;div id=&quot;undergraph&quot;&gt;&lt;/div&gt;
 </diff>
      <filename>graph/index.html</filename>
    </modified>
    <modified>
      <diff>@@ -96,14 +96,24 @@ function loadFilters() {
 
 // callback for the json data.
 function jsonCallback(data) {
-    // TODO: check http status, act thereafter.
-    
     // TODO: hide spinner.
-    
-    graph = pivot(data);
-    var imgUrl = chartImgUrl(graph);
-    $('#graph').html('&lt;img src=&quot;' + imgUrl + '&quot; /&gt;');
-    $('#undergraph').append(' and &lt;a href=&quot;' +imgUrl  +'&quot;&gt;chart&lt;/a&gt;.');
+
+    // check length of data.
+    if (data.length == 0) {
+	$('#errormsg').html('empty dataset.');
+    } else {
+	$('#errormsg').html('' + data.length + ' days of data.');
+	graph = pivot(data);
+	var imgUrl = chartImgUrl(graph);
+	$('#graph').html('&lt;img src=&quot;' + imgUrl + '&quot; /&gt;');
+	$('#undergraph').append(' and &lt;a href=&quot;' +imgUrl  +'&quot;&gt;chart&lt;/a&gt;.');
+    }
+}
+
+function jsonErrorCallback(error) {
+    // TODO: hide spinner.
+    $('#errormsg').append('ERROR: ');
+    $('#errormsg').append(error['error_msg']);
 }
 
 function loadData(t0, t1, unit, d0, d0v, filters) {
@@ -115,9 +125,11 @@ function loadData(t0, t1, unit, d0, d0v, filters) {
 	'&amp;d0v=' + encodeURIComponent(d0v) +
 	'&amp;' + filters +
 	'&amp;jsoncallback=?' +
-	'&amp;jsonp=jsonCallback'
+	'&amp;jsonp=jsonCallback' +
+	'&amp;jsonperror=jsonErrorCallback'
 
     $('#undergraph').html('&lt;a href=&quot;' +dataUrl +'&quot;&gt;raw data&lt;/a&gt;');
+    $('#errormsg').html('');
 
     // TODO: show spinner.
     // TODO: set timeout thread.</diff>
      <filename>graph/js/zohmg.js</filename>
    </modified>
    <modified>
      <diff>@@ -112,7 +112,7 @@ def dump_jsonp(data, jsonp_method=None):
 
     if jsonp_method:
         # client requested data to be wrapped in a function call.
-        return jsonp_method + &quot;(&quot; + jsondata + &quot;)&quot;
+        return jsonp_method+&quot;(&quot;+jsondata+&quot;)&quot;
     else:
         return jsondata
 </diff>
      <filename>src/zohmg/data.py</filename>
    </modified>
    <modified>
      <diff>@@ -25,9 +25,13 @@ from paste.request import parse_formvars
 import zohmg.data
 from zohmg.config import Config
 
-def json_of(error_msg='wha?', status_code=400):
+def json_of(error_msg='wha?', status_code=400, callback=None):
     structure = {'error_msg': error_msg, 'status_code': status_code}
-    return json.dumps(structure)
+    jsondata = json.dumps(structure)
+    if callback:
+        return callback+&quot;(&quot;+jsondata+&quot;)&quot;
+    else:
+        return jsondata
 
 # data application serving at /data.
 class data(object):
@@ -55,6 +59,11 @@ class data(object):
         # interpret the environment.
         params = parse_formvars(environ)
 
+        # error callback?
+        # (hm! can not do json error callbacks on error codes other than 200.)
+        try:    errorcallback = params['jsonperror']
+        except: errorcallback = None
+
         try:
             # hbase query.
             start = time.time()
@@ -63,23 +72,26 @@ class data(object):
         except zohmg.data.DataNotFound, (instance):
             print &gt;&gt;sys.stderr, &quot;Data not found: &quot;, instance.error
             start_response('200 OK', content_type)
-            return json_of(&quot;data not found: &quot; + instance.error, 200)
+            return json_of(&quot;data not found: &quot; + instance.error, 200, errorcallback)
 
         except zohmg.data.MissingArguments, (instance):
             print &gt;&gt;sys.stderr, &quot;400 Bad Request: missing arguments.&quot;
-            start_response('400 Bad Request', content_type)
-            return json_of(&quot;Query is missing arguments: &quot; + instance.error)
+            #start_response('400 Bad Request', content_type)
+            start_response('200 OK', content_type)
+            return json_of(&quot;Query is missing arguments: &quot; + instance.error, 400, errorcallback)
             # TODO: print list of required arguments.
 
         except zohmg.data.NoSuitableProjection, (instance):
             print &gt;&gt;sys.stderr, &quot;400 Bad Request: No suitable projection. &quot;, instance.error
-            start_response('400 Bad Request', content_type)
-            return json_of(&quot; &quot; + instance.error)
+            #start_response('400 Bad Request', content_type)
+            start_response('200 OK', content_type)
+            return json_of(&quot; &quot; + instance.error, 400, errorcallback)
 
         except Exception, e:
             print &gt;&gt;sys.stderr, &quot;Error: &quot;, e
-            start_response('500 Internal Server Error', content_type)
-            return json_of(&quot;egads!, I failed in serving you: &quot; + str(e), 500)
+            #start_response('500 Internal Server Error', content_type)
+            start_response('200 OK', content_type)
+            return json_of(&quot;egads!, I failed in serving you: &quot; + str(e), 500, errorcallback)
 
         elapsed = (time.time() - start)
         sys.stderr.write(&quot;hbase query+prep: %s\n\n&quot; % elapsed)</diff>
      <filename>src/zohmg/middleware/data.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>0e7dd565640375295f92798f64f231956ac0d6e5</id>
    </parent>
  </parents>
  <author>
    <name>Fredrik Mollerstrand</name>
    <email>fredrik@last.fm</email>
  </author>
  <url>http://github.com/zohmg/zohmg/commit/600a20b88e48c9ea0a418b41b936e48e1e5095be</url>
  <id>600a20b88e48c9ea0a418b41b936e48e1e5095be</id>
  <committed-date>2009-06-24T06:41:38-07:00</committed-date>
  <authored-date>2009-06-24T06:41:38-07:00</authored-date>
  <message>graph: prints error if callback set, or size of data set returned.

src/zohmg/middleware/data.py: all status codes are 200 :|
zohmg.js: added error callback.
index.html: added error div.</message>
  <tree>5294ac233a10b9413f629dea165aafd5b73a0876</tree>
  <committer>
    <name>Fredrik Mollerstrand</name>
    <email>fredrik@last.fm</email>
  </committer>
</commit>
