Question

When I try to throw the below forbidden ResponseException from my controller. An exception stating "Processing of the HTTP request resulted in an exception. Please see the HTTP response returned by the 'Response' property of this exception for details." is catched in the catch block of the controller method. Need help in resolving this

throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
Was it helpful?

Solution

Just change your controller implementation to re-throw if it's an HttpResponseException:

try
{
    // action implementation
}
catch (Exception e)
{
    if (e is HttpResponseException)
    {
        throw e;
    }
    // error handling logic
}

But the better answer is that #1 - you should avoid be catching all exceptions, that's bad practice. And #2 - you should use an exception filter instead to do your error handling and not catch exceptions yourself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top