Detailed Exceptions

Developer
Oct 21, 2010 at 2:53 PM

I was having a problem where I was getting some exceptions for schema violations back from FIM, i.e. validation failures, etc, but I couldn't log the information for review later as the exception returned didn't have the detail contained in the response. The work-around I've found is to modify the FaultException returned by ClientHelper.HandleFault(Message message) so that the message content is added to the exception .Data dictionary. I could then easily use this in my overall application error handler/logger.

I don't know if this could be of use to anyone else, but it seems like an oversight not to provide this detail when the client throws an exception.

Here's my modified HandleFault() method:

public static void HandleFault(Message message)
{
	var fault = MessageFault.CreateFault(message, Int32.MaxValue);
	var fe = FaultException.CreateFault(fault,
		typeof(PermissionDeniedFault),
		typeof(AuthenticationRequiredFault),
		typeof(AuthorizationRequiredFault),
		typeof(EndpointUnavailable),
		typeof(FragmentDialectNotSupported),
		typeof(InvalidRepresentationFault),
		typeof(UnwillingToPerformFault),
		typeof(CannotProcessFilter),
		typeof(FilterDialectRequestedUnavailable),
		typeof(UnsupportedExpiration)
	);

	fe.Data.Add("Detail", message.ToString());
	throw fe;
}

This means that when handling the exception, you can access the detail by:

exception.Data["Detail"]

Apr 27, 2015 at 10:51 PM
Hello,

My application as been throwing an exception " Policy prohibits the request from completing" when aim trying to update a person object.
How can i handle this exception, could you please help me ?

Here is my code:

public string ModifyPersonName(string Name)
    {
        // This  shows the basic steps to modify a resource.
        using (DefaultClient client = new DefaultClient())
        {
            string filterName = "/Person[AccountName='" + HttpContext.Current.User.Identity.Name.Split('\\')[1].ToString() + "']";
            System.Security.Principal.WindowsImpersonationContext ctx = null;
            ctx = ((System.Security.Principal.WindowsIdentity)HttpContext.Current.User.Identity).Impersonate();

            //set credentials and refresh schema
            client.RefreshSchema();

            // get the person(s) object(s) to modify
            foreach (RmPerson person in client.Enumerate(filterName))
            {
                // create the object to track changes to the resource
                RmResourceChanges changes = new RmResourceChanges(person);
                try
                {
                    changes.BeginChanges();
                    // change something in the resource
                    person.DisplayName = Name.ToString();
                    // modify the resource on the server
                    client.Put(changes);
                    // the operation succeeded: accept the changes.
                    changes.AcceptChanges();
                    // NOTE: after calling AcceptChanges the RmResourceChanges 
                    // object does not contain any more changes to propagate to
                    // the server.
                }
                catch (FaultException<AuthorizationRequiredFault> ex)
                {
                    // approval required
                    return " Requested Submitted, approval is pending";

                    string jsonResponse = new JavaScriptSerializer().Serialize(ex.Message);
                    string aposUnicode = "\\u0027";
                    return jsonResponse.Replace(aposUnicode, "'"); ;
                }
                catch (FaultException<PermissionDeniedFault>)
                {
                    return "Permissions Denied";
                }
                catch (Exception ex)
                {
                    return ex.Message;
                    // an error occurred, so the resource was not modified; 
                    // rollback the changes.
                    changes.DiscardChanges();
                    //throw;
                }
                finally
                {
                    ctx.Undo();
                }
            }
            return "Requested Submitted, Auto approved";
        }
    }
Thanks,
Sravani
Developer
Apr 28, 2015 at 9:18 AM
Id' suggest the first thing you look at is the question of is the current user allowed to make the desired changes to their own identity? If not then this code should not be executing. If they are meant to be allowed to, then you need some FIM policy to allow it.