Catching XML errors in web service parameters

Hi,

I’m using RoR as a web service to upload data. Unfortunately I’m often
passed poorly formatted XML (it’s written by users, not by machine)
and it often contains errors.

The XML parser that tries to turn the XML into parameters barfs at
some errors (e.g. mismatched opening and closing elements) and I
cannot see how to trap this error and report something meaningful to
the user. At the moment they get a stacktrace or an internal error
message.

Has anyone else come across this problem?

How can I trap these errors for myself?

Allan

bump

On 1/31/08, Allan [email protected] wrote:

Has anyone else come across this problem?
Nah, you’re the first. :slight_smile:

How can I trap these errors for myself?

begin

process xml

rescue
raise “xml error: #{ $!.to_s }” # or whatever you need to do
end


Greg D.
http://destiney.com/

On Feb 1, 11:08 pm, “Greg D.” [email protected] wrote:

On 1/31/08, Allan [email protected] wrote:

Has anyone else come across this problem?

Nah, you’re the first. :slight_smile:

:slight_smile:

How can I trap these errors for myself?

begin

process xml

rescue
raise “xml error: #{ $!.to_s }” # or whatever you need to do
end

Ah, I still don’t quite get it.

As far as see it, my controller is not handling the XML, the RoR
framework is dealing with that for me, thereby populating the params
hash and THEN my controller is invoked. My issue is that malformed
XML is being presented to RoRand I cannot see how to trap the error.

Are you suggesting a different mechanism?

Allan

Anyone?

On 3 Feb 2008, at 21:38, Allan wrote:

:slight_smile:

As far as see it, my controller is not handling the XML, the RoR
framework is dealing with that for me, thereby populating the params
hash and THEN my controller is invoked. My issue is that malformed
XML is being presented to RoRand I cannot see how to trap the error.

Are you suggesting a different mechanism?

If all you want to do is display a friendly error message, then
overriding rescue_action_in_public on that controller might be what
you want to do. Or in 2.0 you can do

class MyController < ApplicationController
rescue_from SomeXmlException, :with => :bad_xml

def bad_xml(exception)
#render some useful message to the user
end
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs