DotNet handling for Web Requests

Does anyone have any ideas how to elegantly handle exceptions within NAV?

I am making a web request (by sending out xml), and at this point I am executing the REST request.

response := request.GetResponse();

If there are no errors, it works wonderfully. 

If it encounters any type of error, I receive this error message: 

"A call to System.Net.HttpWebRequest.GetResponse filed with this message: The remote server returned an error: (400) Bad Request"

For this specific instance, I utilize SoapUI to test hitting the site, and this is the actual error response from them:

<messages xmlns="http://www.canadapost.ca/ws/messages">
   <message>
      <code>7007</code>
      <description>The weight value is invalid.  The weight of each piece must be less than or equal to 30 kg.</description>
   </message>
</messages>

 

So do you have any idea how I can get something helpful to display as an error message in NAV?

Thanks!

Related
Recommended