//----------------------------------------------------------------------- // // Copyright (c) Andrew Arnott. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.Messaging { using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Text; using System.Threading; using System.Threading.Tasks; using Validation; /// /// An exception to represent errors in the local or remote implementation of the protocol /// that includes the response message that should be returned to the HTTP client to comply /// with the protocol specification. /// public class ProtocolFaultResponseException : ProtocolException { /// /// The channel that produced the error response message, to be used in constructing the actual HTTP response. /// private readonly Channel channel; /// /// Initializes a new instance of the class /// such that it can be sent as a protocol message response to a remote caller. /// /// The channel to use when encoding the response message. /// The message to send back to the HTTP client. /// The message that was the cause of the exception. May be null. /// The inner exception. /// The message for the exception. protected internal ProtocolFaultResponseException(Channel channel, IDirectResponseProtocolMessage errorResponse, IProtocolMessage faultedMessage = null, Exception innerException = null, string message = null) : base(message ?? (innerException != null ? innerException.Message : null), faultedMessage, innerException) { Requires.NotNull(channel, "channel"); Requires.NotNull(errorResponse, "errorResponse"); this.channel = channel; this.ErrorResponseMessage = errorResponse; } /// /// Initializes a new instance of the class. /// /// The /// that holds the serialized object data about the exception being thrown. /// The System.Runtime.Serialization.StreamingContext /// that contains contextual information about the source or destination. protected ProtocolFaultResponseException( System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { throw new NotImplementedException(); } /// /// Gets the protocol message to send back to the client to report the error. /// public IDirectResponseProtocolMessage ErrorResponseMessage { get; private set; } /// /// Creates the HTTP response to forward to the client to report the error. /// /// The cancellation token. /// /// The HTTP response. /// public Task CreateErrorResponseAsync(CancellationToken cancellationToken) { return this.channel.PrepareResponseAsync(this.ErrorResponseMessage, cancellationToken); } } }