-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle non success raw http responses (#2541)
* handle non success responses * fix format * nits Co-authored-by: Tingluo Huang <[email protected]> --------- Co-authored-by: Tingluo Huang <[email protected]>
- Loading branch information
1 parent
b9a0b5d
commit c762970
Showing
5 changed files
with
104 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Net; | ||
|
||
namespace Sdk.WebApi.WebApi | ||
{ | ||
public class RawHttpClientResult | ||
{ | ||
public bool IsSuccess { get; protected set; } | ||
public string Error { get; protected set; } | ||
public HttpStatusCode StatusCode { get; protected set; } | ||
public bool IsFailure => !IsSuccess; | ||
|
||
protected RawHttpClientResult(bool isSuccess, string error, HttpStatusCode statusCode) | ||
{ | ||
IsSuccess = isSuccess; | ||
Error = error; | ||
StatusCode = statusCode; | ||
} | ||
} | ||
|
||
public class RawHttpClientResult<T> : RawHttpClientResult | ||
{ | ||
public T Value { get; private set; } | ||
|
||
protected internal RawHttpClientResult(T value, bool isSuccess, string error, HttpStatusCode statusCode) | ||
: base(isSuccess, error, statusCode) | ||
{ | ||
Value = value; | ||
} | ||
|
||
public static RawHttpClientResult<T> Fail(string message, HttpStatusCode statusCode) => new RawHttpClientResult<T>(default(T), false, message, statusCode); | ||
public static RawHttpClientResult<T> Ok(T value) => new RawHttpClientResult<T>(value, true, string.Empty, HttpStatusCode.OK); | ||
} | ||
} |