eabf270d71
Resolve all 622 issues flagged by the enhanced CommentChecker: add missing <returns> tags (incl. the standard phrasing on non-generic Task methods), add missing <summary> tags, and replace misused/redundant <inheritdoc/> on members that override or implement nothing with real documentation. Documentation-only — no behavior change; solution builds clean.
82 lines
3.6 KiB
C#
82 lines
3.6 KiB
C#
using System.Net;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.ExternalSystemGateway;
|
|
|
|
/// <summary>
|
|
/// WP-8: Classifies HTTP errors as transient or permanent.
|
|
/// Transient: connection refused, timeout, HTTP 408/429/5xx.
|
|
/// Permanent: HTTP 4xx (except 408/429).
|
|
/// </summary>
|
|
public static class ErrorClassifier
|
|
{
|
|
/// <summary>
|
|
/// Determines whether an HTTP status code represents a transient failure.
|
|
/// Transient: HTTP 5xx, 408 (Request Timeout) and 429 (Too Many Requests).
|
|
/// Every other non-success status (the remaining 4xx) defaults to permanent —
|
|
/// a permanent failure is the safe default because retrying a 4xx is unlikely to
|
|
/// succeed and risks duplicate side effects.
|
|
/// </summary>
|
|
/// <param name="statusCode">The HTTP status code to classify.</param>
|
|
/// <returns><see langword="true"/> for 5xx, 408, or 429; <see langword="false"/> for all other status codes.</returns>
|
|
public static bool IsTransient(HttpStatusCode statusCode)
|
|
{
|
|
var code = (int)statusCode;
|
|
return code >= 500 || code == 408 || code == 429;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determines whether an exception represents a transient failure.
|
|
/// </summary>
|
|
/// <param name="exception">The exception to classify.</param>
|
|
/// <returns><see langword="true"/> for connection/timeout/cancellation exceptions; <see langword="false"/> otherwise.</returns>
|
|
public static bool IsTransient(Exception exception)
|
|
{
|
|
return exception is HttpRequestException
|
|
or TaskCanceledException
|
|
or TimeoutException
|
|
or OperationCanceledException;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a TransientException for S&F buffering.
|
|
/// </summary>
|
|
/// <param name="message">Human-readable failure description.</param>
|
|
/// <param name="inner">Optional inner exception that caused the transient failure.</param>
|
|
/// <returns>A new <see cref="TransientExternalSystemException"/> wrapping the given details.</returns>
|
|
public static TransientExternalSystemException AsTransient(string message, Exception? inner = null)
|
|
{
|
|
return new TransientExternalSystemException(message, inner);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Exception type that signals a transient failure suitable for store-and-forward retry.
|
|
/// </summary>
|
|
public class TransientExternalSystemException : Exception
|
|
{
|
|
/// <summary>Initializes a new <see cref="TransientExternalSystemException"/> with a message and optional inner exception.</summary>
|
|
/// <param name="message">The error message.</param>
|
|
/// <param name="innerException">Optional inner exception.</param>
|
|
public TransientExternalSystemException(string message, Exception? innerException = null)
|
|
: base(message, innerException) { }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Exception type that signals a permanent failure (should not be retried).
|
|
/// </summary>
|
|
public class PermanentExternalSystemException : Exception
|
|
{
|
|
/// <summary>Gets the HTTP status code that caused the permanent failure, if applicable.</summary>
|
|
public int? HttpStatusCode { get; }
|
|
|
|
/// <summary>Initializes a new <see cref="PermanentExternalSystemException"/> with a message, optional HTTP status code, and optional inner exception.</summary>
|
|
/// <param name="message">The error message.</param>
|
|
/// <param name="httpStatusCode">The HTTP status code that triggered the failure, if available.</param>
|
|
/// <param name="innerException">Optional inner exception.</param>
|
|
public PermanentExternalSystemException(string message, int? httpStatusCode = null, Exception? innerException = null)
|
|
: base(message, innerException)
|
|
{
|
|
HttpStatusCode = httpStatusCode;
|
|
}
|
|
}
|