# Auto\_complete and HTTP errors

**URL:** <https://www.ruby-forum.com/t/auto-complete-and-http-errors/154362>\
**Category:** Rails\
**Created:** [November 28, 2008, 9:44am UTC](https://www.ruby-forum.com/t/auto-complete-and-http-errors/154362 "2008-11-28T09:44:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cameron\_McCloud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e274bd/32.png) [@Cameron\_McCloud](https://www.ruby-forum.com/u/Cameron_McCloud)\
**Post date:** [November 28, 2008, 9:44am UTC](https://www.ruby-forum.com/t/auto-complete-and-http-errors/154362/1 "2008-11-28T09:44:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Cameron\_McCloud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e274bd/32.png) [@Cameron\_McCloud](https://www.ruby-forum.com/u/Cameron_McCloud)\
**Post date:** [November 28, 2008, 9:49am UTC](https://www.ruby-forum.com/t/auto-complete-and-http-errors/154362/2 "2008-11-28T09:49:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Cameron\_McCloud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e274bd/32.png) [@Cameron\_McCloud](https://www.ruby-forum.com/u/Cameron_McCloud)\
**Post date:** [November 28, 2008, 10:48am UTC](https://www.ruby-forum.com/t/auto-complete-and-http-errors/154362/3 "2008-11-28T10:48:38Z")

</div>

On Nov 28, 8:48 am, Cameron McCloud [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![Cameron\_McCloud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e274bd/32.png) [@Cameron\_McCloud](https://www.ruby-forum.com/u/Cameron_McCloud)\
**Post date:** [November 28, 2008, 11:22am UTC](https://www.ruby-forum.com/t/auto-complete-and-http-errors/154362/4 "2008-11-28T11:22:07Z")

</div>

On Nov 28, 10:16 am, Cameron McCloud [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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 🙂 Is your ‘normal’ onComplete  
throwing an exception a possibility ? ( you could put a breakpoint in  
dispatchException).

Fred

---

<div class="post-metadata">

**Author:** ![Cameron\_McCloud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e274bd/32.png) [@Cameron\_McCloud](https://www.ruby-forum.com/u/Cameron_McCloud)\
**Post date:** [November 28, 2008, 11:16am UTC](https://www.ruby-forum.com/t/auto-complete-and-http-errors/154362/5 "2008-11-28T11:16:50Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Cameron\_McCloud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e274bd/32.png) [@Cameron\_McCloud](https://www.ruby-forum.com/u/Cameron_McCloud)\
**Post date:** [November 28, 2008, 12:13pm UTC](https://www.ruby-forum.com/t/auto-complete-and-http-errors/154362/6 "2008-11-28T12:13:51Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Cameron\_McCloud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e274bd/32.png) [@Cameron\_McCloud](https://www.ruby-forum.com/u/Cameron_McCloud)\
**Post date:** [November 28, 2008, 12:32pm UTC](https://www.ruby-forum.com/t/auto-complete-and-http-errors/154362/7 "2008-11-28T12:32:39Z")

</div>

On Nov 28, 11:12 am, Cameron McCloud [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

---

<div class="post-metadata">

**Author:** ![Cameron\_McCloud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e274bd/32.png) [@Cameron\_McCloud](https://www.ruby-forum.com/u/Cameron_McCloud)\
**Post date:** [November 28, 2008, 12:46pm UTC](https://www.ruby-forum.com/t/auto-complete-and-http-errors/154362/8 "2008-11-28T12:46:10Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Cameron\_McCloud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e274bd/32.png) [@Cameron\_McCloud](https://www.ruby-forum.com/u/Cameron_McCloud)\
**Post date:** [November 28, 2008, 11:25am UTC](https://www.ruby-forum.com/t/auto-complete-and-http-errors/154362/9 "2008-11-28T11:25:39Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
