Rama
Rama

Reputation: 307

How to get original exception message to client from web api

I have asp.net Web Api method as following one

[HttpGet]
        public IHttpActionResult GetAllDesignations()
        {
            try
            {
                DesignationApplicationService des = new DesignationApplicationService();
                List<Designation> dsList = des.GetAllDesignations();
                return Ok(dsList);
            }
            catch (Exception ex)
            {

                MyCustomException exception = new MyCustomException(ex, "Error in loading designations", MyEnum.ExceptionType.Error);
                return InternalServerError(exception);
            }
        } 

I am calling this Api method in a C# client application. If an exception occurred in the API method, I have thrown my own custom exception. However it gets only "iternal server (500)" error from the API

Is there an any method to get the original exception in the client application?enter code here

Upvotes: 1

Views: 106

Answers (1)

PercivalMcGullicuddy
PercivalMcGullicuddy

Reputation: 5533

You could try setting the IncludeErrorDetailPolicy configuration to 'Always'.

See this page: http://www.asp.net/web-api/overview/advanced/configuring-aspnet-web-api

Upvotes: 1

Related Questions