From 7e91ee439b42682345df62e744d8534f44f42113 Mon Sep 17 00:00:00 2001 From: Johnny Shields Date: Wed, 10 Dec 2014 13:40:21 +0900 Subject: [PATCH 1/2] Detail error handling in readme --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index 9397d40..66a0f35 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,36 @@ ajax.raw('/foo').then(function(result) { }); ``` +Error Handling +-------------- + +You can handle errors per each request as follows. Note that the jQuery response object for the error is accessible via `.jqXHR`: + +``` +ajax("my/path", { + data: data +}).then(function(response) { + return console.log(response.message); +}, function(error) { + return doSomething(error.jqXHR.responseJSON); +}); +``` + +Global error handling can also be implemented: + +``` +ApplicationRoute = Em.Route.extend({ + init: function() { + this._super(); + return Em.$(document).ajaxError(function(evt, jqxhr) { + return console.log(evt); + }); + } +}); + +export default ApplicationRoute; +``` + Simplified Testing ------------------ From 4f6c8e512601a3a626b626e7b413024e2b6c1ee1 Mon Sep 17 00:00:00 2001 From: Johnny Shields Date: Wed, 14 Jan 2015 05:09:44 +0900 Subject: [PATCH 2/2] Clarify that global error handling using jQuery (not this plugin) --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 66a0f35..4b6df82 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Error Handling You can handle errors per each request as follows. Note that the jQuery response object for the error is accessible via `.jqXHR`: -``` +```js ajax("my/path", { data: data }).then(function(response) { @@ -83,9 +83,9 @@ ajax("my/path", { }); ``` -Global error handling can also be implemented: +Global AJAX error handling can also be implemented using jQuery (does not require this plugin): -``` +```js ApplicationRoute = Em.Route.extend({ init: function() { this._super();