How can i catch an exception which is caused by an post (HttpClient) to an url which wont respond?I tried with
catch (FaultException ex) { FcTracingService.Trace("The application terminated with an error." ex.Message); }
if you are doing a direct HttpClient call you are not using the SDK, afaik catching a Microsoft.Xrm.Sdk exception will not work, that error message is from a generic exception catch? Can you share the relevant part of your code?
using System.ServiceModel; ... HttpClient client = new HttpClient(); ... string jsonPayload = SerializerWrapper.Serialize(Payload); try { StringContent stringContent = new StringContent(jsonPayload, Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync(url, stringContent).Result; FcTracingService.Trace("CockpitAPIRequest response: " response.ToString()); if (response.IsSuccessStatusCode) { string jsonresponse = response.Content.ReadAsStringAsync().Result; return SerializerWrapper.Deserialize(jsonresponse); } else { FcTracingService.Trace("Error in CockpitAPIRequest: " response.ReasonPhrase); if (!this.silent) { throw new InvalidPluginExecutionException(response.ReasonPhrase); } return default(T); } } catch (FaultException ex) { FcTracingService.Trace("The application terminated with an error." ex.Message); } return default(T);
i am using an HttpClient object and also tried to catch System.ServiceModel.HttpClient. Does not work it seems - still bubbles through and i get an exception message in frontend.
can you share additional details? from the trace maybe you are calling a custom api? are you sure the payload is correct? clearly you are getting an error somewhere, instead of FaultException I will catch just Exception (but that is my preference) however don't expect to find there the reason why your call is failing.
Hi,
Just a thought...
Do you really want to use sync plugin for external api ?
I would recommend to use async plugin so that any error occurs will not rollback the entire plugin pipeline.
Async plugin failure can be checked from system jobs
You're right. Dont know why i didnt think of that before. In this case it is ok if the plugin is async and cannot send any message back to the frontend. It just lets the external api know that some record has been deleted. Wheter the api endpoint still exists or not doesnt matter for the crm but with a synconous plugin i would have had to catch that FaultException caused by the httpclient sending to a non existing url. I was able to switch to async registration, added an pre image for some information i need and rewrote the code. Works now! Thanks!
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Sahan Hasitha 193
CA Neeraj Kumar 70
André Arnaud de Cal... 69 Super User 2025 Season 2