-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
66 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System.Collections.Generic; | ||
using System.Net; | ||
|
||
namespace Microsoft.KernelMemory.Diagnostics; | ||
|
||
public static class HttpErrors | ||
{ | ||
// Errors that might disappear by retrying | ||
private static readonly HashSet<int> s_transientErrors = | ||
[ | ||
(int)HttpStatusCode.InternalServerError, | ||
(int)HttpStatusCode.BadGateway, | ||
(int)HttpStatusCode.ServiceUnavailable, | ||
(int)HttpStatusCode.GatewayTimeout, | ||
(int)HttpStatusCode.InsufficientStorage | ||
]; | ||
|
||
public static bool IsTransientError(this HttpStatusCode? statusCode) | ||
{ | ||
return statusCode.HasValue && s_transientErrors.Contains((int)statusCode.Value); | ||
} | ||
|
||
public static bool IsTransientError(int statusCode) | ||
{ | ||
return s_transientErrors.Contains(statusCode); | ||
} | ||
|
||
public static bool IsFatalError(this HttpStatusCode? statusCode) | ||
{ | ||
return statusCode.HasValue && IsError(statusCode) && !IsTransientError(statusCode); | ||
} | ||
|
||
public static bool IsFatalError(int statusCode) | ||
{ | ||
return IsError(statusCode) && !IsTransientError(statusCode); | ||
} | ||
|
||
private static bool IsError(this HttpStatusCode? statusCode) | ||
{ | ||
return statusCode.HasValue && (int)statusCode.Value >= 400; | ||
} | ||
|
||
private static bool IsError(int statusCode) | ||
{ | ||
return statusCode >= 400; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ public enum ResultType | |
{ | ||
Success = 0, | ||
TransientError = 1, | ||
UnrecoverableError = 2, | ||
FatalError = 2, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters