// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics.Contracts;
using System.Net.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Properties;
namespace System.Web.Http.ExceptionHandling
{
/// Represents the context within which unhandled exception logging occurs.
public class ExceptionLoggerContext
{
private readonly ExceptionContext _exceptionContext;
///
/// Initializes a new instance of the class using the values provided.
///
/// The exception context.
public ExceptionLoggerContext(ExceptionContext exceptionContext)
{
if (exceptionContext == null)
{
throw new ArgumentNullException("exceptionContext");
}
_exceptionContext = exceptionContext;
}
/// Gets the exception context providing the exception and related data.
public ExceptionContext ExceptionContext
{
get { return _exceptionContext; }
}
/// Gets the exception caught.
public Exception Exception
{
get { return _exceptionContext.Exception; }
}
/// Gets the catch block in which the exception was caught.
public ExceptionContextCatchBlock CatchBlock
{
get { return _exceptionContext.CatchBlock; }
}
/// Gets the request being processed when the exception was caught.
public HttpRequestMessage Request
{
get { return _exceptionContext.Request; }
}
/// Gets the request context in which the exception occurred.
public HttpRequestContext RequestContext
{
get { return _exceptionContext.RequestContext; }
}
///
/// Gets or sets a value indicating whether the exception can subsequently be handled by an
/// to produce a new response message.
///
///
///
/// Some exceptions are caught after a response is already partially sent, which prevents sending a new
/// response to handle the exception. In such cases, will be called to log the
/// exception, but the will not be called.
///
///
/// If this value is , exceptions from this catch block will be provided to both
/// and . If this value is
/// see langword="false"/>, exceptions from this catch block cannot be handled and will only be provided to
/// .
///
///
public bool CallsHandler
{
get
{
Contract.Assert(_exceptionContext != null);
ExceptionContextCatchBlock catchBlock = _exceptionContext.CatchBlock;
return catchBlock.CallsHandler;
}
}
}
}