<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>frameworks/foundation/fixtures/malformed.json</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -133,14 +133,24 @@ SC.Response = SC.Object.extend(
   encodedBody: null,
   
   /**
-    Response body.  If isJSON was set, will be parsed automatically.
+    Response body. If isJSON was set, will be parsed automatically.
     
-    @property {Hash|String}
+    @response {Hash|String|SC.Error} the response body or the parsed JSON.
+      Returns a SC.Error instance if there is a JSON parsing error.
   */
   body: function() {
     // TODO: support XML
     var ret = this.get('encodedBody');
-    if (ret &amp;&amp; this.get('isJSON') &amp;&amp; !ret.match(/^\s*$/)) ret = SC.json.decode(ret);
+    if (ret &amp;&amp; this.get('isJSON')) {
+      try {
+        ret = SC.json.decode(ret);
+      } catch(e) {
+        return SC.Error.create({
+          message: e.name + ': ' + e.message,
+          label: 'Response',
+          errorValue: this });
+      }
+    }
     return ret;
   }.property('encodedBody').cacheable(),
   </diff>
      <filename>frameworks/foundation/system/response.js</filename>
    </modified>
    <modified>
      <diff>@@ -83,6 +83,33 @@ test(&quot;Test Asynchronous GET Request, auto-deserializing JSON&quot;, function() {
 
 });
 
+test(&quot;Test auto-deserializing malformed JSON&quot;, function() {
+  request = SC.Request.getUrl(sc_static('malformed.json')).set('isJSON', YES);
+
+  var timer = setTimeout(function() {
+    ok(false, 'response did not invoke notify()');
+    window.start();
+  }, 1000);
+  
+  request.notify(this, function(response) {
+    ok(SC.ok(response), 'response should not be error');
+    
+    try {
+      var body = response.get('body');
+      ok(!SC.ok(body), 'body should be an error');
+    } catch(e) {
+      ok(false, 'getting the body should not throw an exception');
+    }
+    
+    clearTimeout(timer);
+    window.start();
+  });
+  
+  request.send();
+
+  stop();
+});
+
 test(&quot;Test Synchronous GET Request, auto-deserializing JSON&quot;, function() {
   request.set(&quot;isAsynchronous&quot;, false);
   request.set(&quot;isJSON&quot;, true);</diff>
      <filename>frameworks/foundation/tests/system/request.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>7c9b0d8d2dadebb410a20221c6f16b01d4d3cefe</id>
    </parent>
  </parents>
  <author>
    <name>Martin Ottenwaelter</name>
    <email>martin.ottenwaelter@gmail.com</email>
  </author>
  <url>http://github.com/sproutit/sproutcore/commit/d380ed008e0cd42b6b05e21a179a4de390550c1d</url>
  <id>d380ed008e0cd42b6b05e21a179a4de390550c1d</id>
  <committed-date>2009-11-06T01:12:55-08:00</committed-date>
  <authored-date>2009-11-06T01:12:55-08:00</authored-date>
  <message>response.get('body') should not throw an exception when it tries
to decode malformed JSON. Return a SC.Error instance instead.</message>
  <tree>14511c95d0344a8636fae65c12278d97c54c6239</tree>
  <committer>
    <name>Martin Ottenwaelter</name>
    <email>martin.ottenwaelter@gmail.com</email>
  </committer>
</commit>
