using System;
namespace Microsoft.AspNetCore.NodeServices.HostingModels
{
///
/// Represents an exception caused by invoking Node.js code.
///
public class NodeInvocationException : Exception
{
///
/// If true, indicates that the invocation failed because the Node.js instance could not be reached. For example,
/// it might have already shut down or previously crashed.
///
public bool NodeInstanceUnavailable { get; private set; }
///
/// If true, indicates that even though the invocation failed because the Node.js instance could not be reached
/// or needs to be restarted, that Node.js instance may remain alive for a period in order to complete any
/// outstanding requests.
///
public bool AllowConnectionDraining { get; private set;}
///
/// Creates a new instance of .
///
/// A description of the exception.
/// Additional information, such as a Node.js stack trace, representing the exception.
public NodeInvocationException(string message, string details)
: base(message + Environment.NewLine + details)
{
}
///
/// Creates a new instance of .
///
/// A description of the exception.
/// Additional information, such as a Node.js stack trace, representing the exception.
/// Specifies a value for the flag.
/// Specifies a value for the flag.
public NodeInvocationException(string message, string details, bool nodeInstanceUnavailable, bool allowConnectionDraining)
: this(message, details)
{
// Reject a meaningless combination of flags
if (allowConnectionDraining && !nodeInstanceUnavailable)
{
throw new ArgumentException(
$"The '${ nameof(allowConnectionDraining) }' parameter cannot be true " +
$"unless the '${ nameof(nodeInstanceUnavailable) }' parameter is also true.");
}
NodeInstanceUnavailable = nodeInstanceUnavailable;
AllowConnectionDraining = allowConnectionDraining;
}
}
}