Jump to content


Photo

faultString, faultStr, faultSTR


  • Please log in to reply
1 reply to this topic

#1 Matthew Van Sickler

Matthew Van Sickler
  • Members
  • 5 posts

Posted 11 April 2015 - 06:55 PM

I gotta say it's pretty frustrating to write error handling code and logging around the Barracuda API's responses when the fault string comes back in at least 3 different ways (that I've run across so far).   faultCode seems to be consistent but why in the world is the fault string reported back in different ways?  I'm baffled why you would do this, especially in a format (XML) that is case sensitive.

 

Has anyone else run into this writing your scripts?  How did you handle it?

 

I suppose I can convert to a string and do a case-insensitive search for "faultstr" then parse the result but that kinda defeats the purpose of having all this stuff in XML in the first place.



#2 Matthew Van Sickler

Matthew Van Sickler
  • Members
  • 5 posts

Posted 12 April 2015 - 04:16 PM

I wrote a simple powershell function to work around this.  I pass the response XML and just iterate through the various faultStr variants until I get a hit, then return the result.  I will just keep adding "faultString" variants as I find them:

Function GetFaultString{
    param(
        $xmlinput
    )

    $faultString = ($xmlinput | Select-Xml -XPath "//member[name = 'faultStr']" | Select-Object -ExpandProperty node | Select-Object -ExpandProperty innertext) -replace "faultStr",""
    if($faultString){return $faultString}

    $faultString = ($xmlinput | Select-Xml -XPath "//member[name = 'faultSTR']" | Select-Object -ExpandProperty node | Select-Object -ExpandProperty innertext) -replace "faultSTR",""
    if($faultString){return $faultString}

    $faultString = ($xmlinput | Select-Xml -XPath "//member[name = 'faultString']" | Select-Object -ExpandProperty node | Select-Object -ExpandProperty innertext) -replace "faultString",""
    if($faultString){return $faultString}

    return "faultString not found"
}