web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Suggested Answer

Catch server's response message in plugin

(0) ShareShare
ReportReport
Posted on by 165

Hello,

I've written a plugin which consumes a business central web service.

It works great when the server's response is 200.

When the server's reponse is 500 (internal server error) I need to show the user the error message. The problem is that I think I'm not getting the error message.

When I consume the web service from postman or Wizdler, I get an error like this:

pastedimage1632745138851v1.png

When I consume the web service from the plugin, I only get this:

pastedimage1632745264667v2.png

How am I supposed to get the error and show it to user?

here is part of the code:

                       HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                        if (response.StatusCode == HttpStatusCode.OK)
                        {

                            Stream responseStream = response.GetResponseStream();
                            string responseStr = new StreamReader(responseStream).ReadToEnd();

                            string result = responseStr;
                            context.OutputParameters["resultString"] = result;
                        }
                        else if(response.StatusCode == HttpStatusCode.InternalServerError)
                        {
                            string result = response.StatusDescription;
                            context.OutputParameters["resultString"] = result;
                        }
                    }

                }

                catch (FaultException ex)
                {
                    throw new InvalidPluginExecutionException("An error occurred in FollowUpPlugin.", ex);
                }

                catch (Exception ex)
                {
                    tracingService.Trace("FollowUpPlugin: {0}", ex.ToString());
                    throw;
                }
            }

I have the same question (0)
  • Suggested answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at

    Hi,

    In code only use Exception catch and in the same catch try to add below code:

    throw new InvalidPluginExecutionException(ex.message);

    Thanks,
    Pradeep.

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.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
KristineRisberg Profile Picture

KristineRisberg 37

#2
11manish Profile Picture

11manish 35

#3
Manoj - ManoVerse Profile Picture

Manoj - ManoVerse 21 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans