Pregunta

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));
¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top