How to get rid of http errors and network errors in ASP.NET Core Web API

I used VS 2022 to build API to take information and now it is using by the clients.

The controller class and the action method are shown here:

[Route("[controller]")]
[ApiController]
public class ABCController : ControllerBase
{
    [HttpPost("[action]")]
    [ProducesResponseType(typeof(Unit), 200)]
    public async Task<object[]> MoreDetails(SearchInfo sc)
    {
         Error error = new Error(1, "");

         Unit[] units = null;
         bool authavail = true;

         try
         {
             if (CheckPassword())
             {
                    MoreDetailsInfo lobjSearch = new MoreDetailsInfo (this._iconfiguration);

                    if (this._iconfiguration["trackid"] == "1")
                    {
                        authavail = lobjSearch.Ischeck(sc);
                    }

                    if (authavail)
                    {
                        units = lobjSearch.GetInfo(sc);

                        if (units != null && units.Length == 1)
                        {
                            if (units[0].IsGatewayError)
                            {
                                Error[] arrError = new Error[1];
                                arrError[0] = new Error();
                                arrError[0].ErrorNumber = -3;
                                arrError[0].ErrorMessage = "Error in response";

                                return arrError;
                            }
                        }
                        else if (units == null)
                        {
                            Error[] arrError = new Error[1];
                            arrError[0] = new Error();
                            arrError[0].ErrorMessage = "unable to take availabilities";

                            return arrError;
                        }
                    }
                    else
                    {
                        Error[] arrError = new Error[1];
                        arrError[0] = new Error();
                        arrError[0].ErrorMessage = "Invalid destination!";

                        return arrError;
                    }
                }
                else
                {
                    Error[] arrError = new Error[1];
                    arrError[0] = new Error();
                    arrError[0].ErrorNumber = -3;
                    arrError[0].ErrorMessage = "Authentication failed...";

                    return arrError;
                } 
        }
        catch (Exception ex)
        {
        }

        return units;
    }
}

But the clients informed me that they are taking network errors and http errors. How do I sort out those issues?

What steps should I need to perform?

Thanks in advance

Leave a Comment