Auto_complete and HTTP errors

Hi,

I have a simple example in Rails 2.1.2, 2.2.2 using the auto_complete
plugin. It works wonderfully. However, I was wondering how it would
handle errors. For example, if for some reason a person couldn’t be
found, the HTTP request will come back with a 404

def auto_complete_for_people_foo
# Cause a deliberate error
people = Person.find(22222) # doesn’t exist
. . .
end

Or there might be a syntax error in the code and we get a 500 error
back.

def auto_complete_for_people_foo
# Cause a deliberate error
asflksajflasjlf # Not valid Ruby code
. . .
end

For other AJAX functionality in our application (e.g. form_remote_tag)
we have global AJAX repsonders as follows:

Ajax.Responders.register({
onComplete: function(transport) {
console.info(“COMPLETE”);
Element.hide(‘spinner’);
if (transport.transport.status == 0 || transport.transport.status ==
12029) {
// Lost connection as reported in Firefox (0) or IE (12029)
alert(“The connection with the server has been lost.”);
console.info(“LOST CONNECTION”);
} else if (transport.transport.status != 200 ) {
alert(String.format(“The server has reported an error with code
{0}”, transport.transport.status));
console.info(“ERROR”);
}
},
onCreate: function() {
Element.show(‘spinner’);
console.info(“LOADING…”);
}
});

For auto_complete, the onCreate callback gets invoked, but the
onComplete one never does. I’ve checked this in Firebug - I can see
the 404 or 500 POST errors, but I the

Does anyone have any ideas or areas they can point me to?

TIA

Cam.

The last bit should have read:

For auto_complete, the onCreate callback gets invoked, but the
onComplete one never does. I’ve checked this in Firebug - I can see
the 404 or 500 POST errors, but the onComplete responder never kicks
in.

On Nov 28, 8:48 am, Cameron McCloud [email protected] wrote:

The last bit should have read:

For auto_complete, the onCreate callback gets invoked, but the
onComplete one never does. I’ve checked this in Firebug - I can see
the 404 or 500 POST errors, but the onComplete responder never kicks
in.

That’s weird. Prototype itself uses that to maintain the value of
Ajax.activeRequestCount
Is that value going up and down as it should?
If you look at the code, one thing that would screw this over would be
if the onComplete callback for that particular request threw an
exception

Fred

On Nov 28, 10:16 am, Cameron McCloud [email protected]
wrote:

When I CTRL-F5 to start off afresh, the Ajax.activeRequestCount is 0.

If I type in my name very slowly into the edit box, the count is now 7

  • it is never decremented. When my code is running normally (i.e. I’m
    not deliberately forcing errors), the count always returns to zero.

So it’s not just your responder :slight_smile: Is your ‘normal’ onComplete
throwing an exception a possibility ? ( you could put a breakpoint in
dispatchException).

Fred

When I CTRL-F5 to start off afresh, the Ajax.activeRequestCount is 0.

If I type in my name very slowly into the edit box, the count is now 7

  • it is never decremented. When my code is running normally (i.e. I’m
    not deliberately forcing errors), the count always returns to zero.

On Nov 28, 9:48 am, Frederick C. [email protected]

I put a breakpoint on dispatchException and it hits that with the
following:

TypeError: element.hasClassName is not a function
message=element.hasClassName is not a function.

The line that triggered the exception is in prototype.js line 1322
(Latest Prototype.js 1.6.0.3)

However, I also get this even if I don’t have any Ajax responders set
up.

On Nov 28, 10:24 am, Cameron McCloud [email protected]

On Nov 28, 11:12 am, Cameron McCloud [email protected]
wrote:

I put a breakpoint on dispatchException and it hits that with the
following:

TypeError: element.hasClassName is not a function
message=element.hasClassName is not a function.

The line that triggered the exception is in prototype.js line 1322
(Latest Prototype.js 1.6.0.3)

You need to crawl up the stack to see who called that. My guess is
that your onComplete callback does something that doesn’t make sense
when the response wasn’t a 200.

Fred

On reading the Prototype docs (something I should have done earlier),
there’s another Responder for handling exceptions - onException. This
does get called and through it I can let the user know that something
went wrong. It doesn’t seem to tell me if the problem is a 404, 500
and I can’t tell if the server is no longer available, but it’s a
start.

Thanks for all your help Frederick.

Cameron.

On Nov 28, 11:12 am, Cameron McCloud [email protected]

Strangely enough when the focus is on the auto complete edit field in
Firefox and I ALT-TAB to my editor, another AJAX request is made, but
this time the onComplete gets called and I get the alert message box

On Nov 28, 10:21 am, Frederick C. [email protected]