Getting the Restriction Codes

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


Comments

5 responses to “Getting the Restriction Codes”

  1. Doug,
    I have used your code above succesfully to trap an exception.
    The exception generates a RESTRICTION ERROR of 1633. The generated child RESTRICTION CODE is 3000.
    Do you have any tables that shine light on what the restriction code mean. In my case the 3000?

  2. It’s in the SDK documentation. The .chm has a page called “Restriction Codes”

  3. Larry Daubenspeck Avatar
    Larry Daubenspeck

    Doug,
    The code I’m getting is 1008, and the .chm skips from 1007 to 1009. Any ideas what 1008 is?

  4. Larry Daubenspeck Avatar
    Larry Daubenspeck

    Nevermind – I found it.

  5. pregunton Avatar
    pregunton

    is valid
    SoapException
    Using the Detail Property to Handle Specific Errors
    https://msdn.microsoft.com/en-us/library/ms153645.aspx
    ?

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading