
If you ever come across errors 1092, 1387, or 1633, you need to look at the restriction codes to figure out what the problems are. Basically these codes are telling you, "We can't fully describe the problem with a single error code so we provided extra information."
Error codes are limited by the fact that there can be only one of them when something goes wrong. For cases where multiple things go wrong, extra data is contained in the restriction codes.
This mechanism comes in handy when an operation is being done on multiple objects at once or multiple things can go wrong. That way everything can be presented to the user at once instead of making them fix things one at a time.
As a programmer, you probably just want some code that you can copy and paste into your project. So here you go. As always, I'm eager to please. If the Exception is coming from the vault server, the following function will return both the Vault server error code and any restriction codes.
|
// for my C# brethren public static void GetErrorAndRestrictionCodesString(Exception e, out string errorCode, out List<string> restrictionCodes) { SoapException se = e as SoapException; errorCode = null; restrictionCodes = new List<string>(); string [] restrictionErrors = new string [] { "1092", "1387", "1633" }; if (se != null) { try { errorCode = se.Detail["sl:sldetail"]["sl:errorcode"].InnerText.Trim(); if (restrictionErrors.Contains(errorCode)) { XmlNodeList nodes = se.Detail["sl:sldetail"]["sl:restrictions"].ChildNodes; foreach (XmlNode node in nodes) { if (node.Name == "sl:restriction") { XmlElement element = node as XmlElement; if (element != null) restrictionCodes.Add(element.GetAttribute("sl:code")); } } } } catch { } } }
|
|
' VB goodness Public Shared Sub GetErrorAndRestrictionCodesString(ByVal e As Exception, _ ByRef errorCode As String, ByRef restrictionCodes As List(Of String)) Dim se As SoapException = TryCast(e, SoapException) errorCode = Nothing restrictionCodes = New List(Of String)() Dim restrictionErrors As String() = New String() {"1092", "1387", "1633"} If se IsNot Nothing Then Try errorCode = se.Detail("sl:sldetail")("sl:errorcode").InnerText.Trim() If restrictionErrors.Contains(errorCode) Then Dim nodes As XmlNodeList = se.Detail("sl:sldetail")("sl:restrictions").ChildNodes For Each node As XmlNode In nodes If node.Name = "sl:restriction" Then Dim element As XmlElement = TryCast(node, XmlElement) If element IsNot Nothing Then restrictionCodes.Add(element.GetAttribute("sl:code")) End If End If Next End If Catch End Try End If End Sub
|
