// 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.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Web.Http.Properties;
namespace System.Web.Http
{
///
/// An exception that allows for a given
/// to be returned to the client.
///
[SuppressMessage("Microsoft.Usage", "CA2237:MarkISerializableTypesWithSerializable", Justification = "This type is not meant to be serialized")]
[SuppressMessage("Microsoft.Usage", "CA2240:Implement ISerializable correctly", Justification = "This type has no serializable state")]
[SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors", Justification = "HttpResponseException is not a real exception and is just an easy way to return HttpResponseMessage")]
public class HttpResponseException : Exception
{
///
/// Initializes a new instance of the class.
///
/// The status code of the response.
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Instance is disposed elsewhere")]
public HttpResponseException(HttpStatusCode statusCode)
: this(new HttpResponseMessage(statusCode))
{
}
///
/// Initializes a new instance of the class.
///
/// The response message.
public HttpResponseException(HttpResponseMessage response)
: base(SRResources.HttpResponseExceptionMessage)
{
if (response == null)
{
throw Error.ArgumentNull("response");
}
Response = response;
}
///
/// Gets the to return to the client.
///
public HttpResponseMessage Response { get; private set; }
}
}