Skip to content

Commit

Permalink
Request.JSON now catches errors thrown by JSON.decode and fires the f…
Browse files Browse the repository at this point in the history
…ailure event.
  • Loading branch information
anutron committed Aug 6, 2009
1 parent 1a0d5b5 commit b14d56b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Docs/Request/Request.JSON.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ Fired when the request completes. This overrides the signature of the Request su
alert(person.height); //Alerts "170 cm".
alert(person.weight); //Alerts "120 kg".
}}).get({'firstName': 'John', 'lastName': 'Doe'});

### failure

Request.JSON fires the *failure* event when the JSON value is not parsed due to security tests. If the option for *secure* is set to true and the JSON value is *not* secure, [JSON.decode][] will throw an exception. Request.JSON catches this and fires its *failure* event.

[JSON.decode]: /core/docs/Utilities/JSON#JSON:decode
10 changes: 7 additions & 3 deletions Source/Request/Request.JSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ Request.JSON = new Class({
},

success: function(text){
this.response.json = JSON.decode(text, this.options.secure);
this.onSuccess(this.response.json, text);
try {
this.response.json = JSON.decode(text, this.options.secure);
this.onSuccess(this.response.json, text);
} catch(error) {
this.failure();
}
}

});
});

0 comments on commit b14d56b

Please sign in to comment.