/// <summary> /// Initializes an instance of the <see cref="SteamCommunityDataClient"/> class with a specific handler and settings. /// </summary> /// <param name="handler">The HTTP handler stack to use for sending requests.</param> /// <param name="disposeHandler"> /// true if the inner handler should be disposed of by <see cref="Dispose"/>, /// false if you intend to reuse the inner handler. /// </param> /// <param name="telemetryClient">The telemetry client to use for reporting telemetry.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="telemetryClient"/> is null. /// </exception> internal SteamCommunityDataClient(HttpMessageHandler handler, bool disposeHandler, TelemetryClient telemetryClient) { http = new ProgressReporterHttpClient(handler, disposeHandler, telemetryClient) { BaseAddress = new Uri("http://steamcommunity.com/") }; }
/// <summary> /// Initializes a new instance of the <see cref="SteamWebApiClient"/> class with a specific handler. /// </summary> /// <param name="handler">The HTTP handler stack to use for sending requests.</param> /// <param name="disposeHandler"> /// true if the inner handler should be disposed of by <see cref="Dispose"/>, /// false if you intend to reuse the inner handler. /// </param> /// <param name="telemetryClient">The telemetry client to use for reporting telemetry.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="telemetryClient"/> is null. /// </exception> internal SteamWebApiClient(HttpMessageHandler handler, bool disposeHandler, TelemetryClient telemetryClient) { http = new ProgressReporterHttpClient(handler, disposeHandler, telemetryClient) { BaseAddress = new Uri("https://api.steampowered.com/") }; }
/// <summary> /// Indicates if an exception is a transient fault for <see cref="SteamCommunityDataClient"/>. /// </summary> /// <param name="ex">The exception to check.</param> /// <returns> /// true, if the exception is a transient fault for <see cref="SteamCommunityDataClient"/>; otherwise, false. /// </returns> public static bool IsTransient(Exception ex) { if (ex is HttpRequestStatusException hrse) { switch ((int)hrse.StatusCode) { case 408: // Request Timeout case 429: // Too Many Requests case 500: // Internal Server Error case 502: // Bad Gateway case 503: // Service Unavailable case 504: // Gateway Timeout return(true); } } else if (ex is IOException ioe) { if (ioe.InnerException is SocketException se) { switch (se.SocketErrorCode) { case SocketError.ConnectionReset: case SocketError.TimedOut: return(true); } } } return(ProgressReporterHttpClient.IsTransient(ex)); }
public void ReturnsFalse() { // Arrange var ex = new Exception(); // Act var isTransient = ProgressReporterHttpClient.IsTransient(ex); // Assert Assert.False(isTransient); }
public void ExIsHttpRequestExceptionAndInnerExceptionIsNotWebException_ReturnsFalse() { // Arrange var inner = new Exception(); var ex = new HttpRequestException(null, inner); // Act var isTransient = ProgressReporterHttpClient.IsTransient(ex); // Assert Assert.False(isTransient); }
public void ExIsHttpRequestExceptionAndInnerExceptionIsWebExceptionAndStatusIsTransient_ReturnsTrue(WebExceptionStatus status) { // Arrange var inner = new WebException(null, status); var ex = new HttpRequestException(null, inner); // Act var isTransient = ProgressReporterHttpClient.IsTransient(ex); // Assert Assert.True(isTransient); }
public void ExIsHttpRequestExceptionAndInnerExceptionIsWebExceptionAndStatusIsNotTransient_ReturnsFalse() { // Arrange var status = WebExceptionStatus.NameResolutionFailure; var inner = new WebException(null, status); var ex = new HttpRequestException(null, inner); // Act var isTransient = ProgressReporterHttpClient.IsTransient(ex); // Assert Assert.False(isTransient); }
/// <summary> /// Indicates if an exception is a transient fault for <see cref="SteamWebApiClient"/>. /// </summary> /// <param name="ex">The exception to check.</param> /// <returns> /// true, if the exception is a transient fault for <see cref="SteamWebApiClient"/>; otherwise, false. /// </returns> public static bool IsTransient(Exception ex) { if (ex is HttpRequestStatusException hrse) { // https://partner.steamgames.com/doc/webapi_overview/responses#status_codes switch ((int)hrse.StatusCode) { case 408: // Request Timeout case 429: // Too Many Requests You are being rate limited. case 500: // Internal Server Error An unrecoverable error has occurred, please try again. case 502: // Bad Gateway case 503: // Service Unavailable Server is temporarily unavailable, or too busy to respond. Please wait and try again later. case 504: // Gateway Timeout return(true); } } return(ProgressReporterHttpClient.IsTransient(ex)); }
/// <summary> /// Initializes an instance of the <see cref="UgcHttpClient"/> class. /// </summary> /// <param name="handler">The HTTP handler stack to use for sending requests.</param> /// <param name="disposeHandler"> /// true if the inner handler should be disposed of by <see cref="Dispose"/>, /// false if you intend to reuse the inner handler. /// </param> /// <param name="telemetryClient">The telemetry client to use for reporting telemetry.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="telemetryClient"/> is null. /// </exception> internal UgcHttpClient(HttpMessageHandler handler, bool disposeHandler, TelemetryClient telemetryClient) { http = new ProgressReporterHttpClient(handler, disposeHandler, telemetryClient); }
/// <summary> /// Indicates if an exception is a transient fault for <see cref="UgcHttpClient"/>. /// </summary> /// <param name="ex">The exception to check.</param> /// <returns> /// true, if the exception is a transient fault for <see cref="UgcHttpClient"/>; otherwise, false. /// </returns> public static bool IsTransient(Exception ex) { return(ProgressReporterHttpClient.IsTransient(ex)); }
public ProgressReporterHttpClientTests() { httpClient = new ProgressReporterHttpClient(handler, true, telemetryClient); }