Spry Error Callback Example

This post is more than 2 years old.

Today's entry is from a guest blogger. Now before folks get all excited, I don't have a "real" concept of guest blogging here. Rather - he had a good problem with Spry and he shared his solution with me. He doesn't have a blog yet (hmm, someone should consider making a service so it is easy for folks to use BlogCFC w/o needing a real host, hmmm indeed) so I said I'd blog it for him.

Daniel Budde II (wraith) had this to share about error handling in Spry. I blogged about states in Spry before - and there is a simple way to create an error state for Spry, but what if you want a more controlled result for Spry?

From Daniel:

I made a post about it on the Adobe Spry forum. It's not the clearest post, but I just thought I would give it to you to look at if you want. I'm interested in the responses people will give.


Ok, I had a problem with it in IE because IE's XMLHttpRequest object has a send() method that will throw an error if the status code from the web server is not "200". When it throws the error it prevents the "synchronous" execution of the Spry.Utils.loadURL.callback method. So, to get around this you need to use "asynchronous" mode which will rely on the "onreadystatechange" method and will then call the callback method which will in turn call a custom error handler if you have one set.

Here is my example:

var optionsObj = new Object();

optionsObj.errorCallback = ShowError;

Spry.Utils.loadURL("GET", url, true, ValidateForm, optionsObj);

There is a list of available options that you can set in the SpryData.js file and here those are:

[ "method", "url", "async", "username", "password", "postData", "successCallback", "errorCallback", "headers", "userData", "xhRequest" ]

Obviously some of those are used and setup no matter what (method, url, async).

Ray again: Just in case it wasn't clear, the ShowError variable is a function that is a called when the error occurs.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Daniel Budde II (VVraith) posted on 9/7/2006 at 11:39 PM

So, a good bit of news that I shared with Ray about this, is that I posted on the Adobe forums and an Adobe tech did reponds saying the IE (synchronous) issue does appear to be a bug and he has entered it as such.

That is good to know so that later we can use our custom error handlers synchronously as well as asychronous.

Thanks Ray for the post. Your contributions to the community are always appreciated. :)

Comment 2 by Raymond Camden posted on 9/7/2006 at 11:43 PM

Hey, you wrote the post. ;) Now if I can only have all my posts auto-generated...

Comment 3 by Ron Gowen posted on 9/8/2006 at 1:53 AM

Ooops, I just Wraithed all over the couch!

Sorry, just had to throw that out there.

Nice work Daniel.

Comment 4 by test posted on 9/25/2006 at 6:34 PM