Utilizing the EpicorRestAPI (Core), is there a way to return the response content instead of throwing an exception on bad request status

We recently uplifted our Epicor API from .NET Framework 4.8 to .NET 8. I have a snippet of code that used to work, but a change made to the EpicorRestV1 library is now causing a break:

respData = EpicorRestV1.DynamicPost("Erp.BO.CustShipSvc", "UpdateMaster", postData);
if (respData.HttpStatus != null)
{
    if ((respData.HttpStatus == 400) || (respData.HttpStatus == 500))
    {
        String errorMsg = respData.ReasonPhrase.Value + " " + respData.ErrorMessage.Value;
        throw new Exception("Erp.BO.CustShipSvc[Prep]: " + errorMsg);
    }
}

Unfortunately, if the request responds with a “BadRequest” Http Status, the EpicorRestV1.DynamicPost(“”) library will throw an exception. This prevents me from actually seeing the error in the response body. In my case, my Bad Requests are a result of misconfigured products. It would be useful to be able to inform our Epicor users that a product needs some corrections, but unfortunately, because the exception is thrown before the response content is returned, I can’t actually know for certain what the error is.

I am (attempting to) attach a screenshot of the EpicorRestV1 PostJSON code to show where it returns the error

I am wondering if there is a work around that will allow me to see the error in the response instead of throwing the exception.

This use to work before the upgrade… so we’re wondering if there’s a difference with how the core variant of the library bubbles up the error.

@josecgomez

V1 is so old

You should upgrade to the new version of the library not using V1

I can try to look at it but honestly that RestV1 is just there for really old legacy apps

2 Likes