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:
When I consume the web service from the plugin, I only get this:
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; } }
Hi,
In code only use Exception catch and in the same catch try to add below code:
throw new InvalidPluginExecutionException(ex.message);
Thanks,
Pradeep.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,867 Super User 2024 Season 2
Martin Dráb 229,173 Most Valuable Professional
nmaenpaa 101,156