-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove StatusCode exceptions. Refactoring. (#44)
- Loading branch information
1 parent
2e09fcc
commit 4a85b99
Showing
23 changed files
with
116 additions
and
207 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
src/Arbus.Network/Exceptions/NoNetoworkConnectionException.cs
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
namespace Arbus.Network.Exceptions; | ||
|
||
public class NoNetoworkConnectionException : NetworkException | ||
public class NoNetworkConnectionException : NetworkException | ||
{ | ||
public NoNetoworkConnectionException() : base("No network connection.") | ||
public NoNetworkConnectionException() : base("No network connection.") | ||
{ | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,50 @@ | ||
using System.Net.Http.Headers; | ||
|
||
namespace Arbus.Network; | ||
|
||
public class HttpClientContext : IHttpClientContext | ||
{ | ||
protected INativeHttpClient _nativeHttpClient; | ||
|
||
public HttpClientContext(INativeHttpClient httpClientHandler) | ||
{ | ||
_nativeHttpClient = httpClientHandler; | ||
} | ||
|
||
public async Task RunEndpoint(ApiEndpoint endpoint) | ||
{ | ||
using var responseMessage = await RunEndpointInternal(endpoint).ConfigureAwait(false); | ||
} | ||
|
||
public async Task<TResponse> RunEndpoint<TResponse>(ApiEndpoint<TResponse> endpoint) | ||
{ | ||
using var responseMessage = await RunEndpointInternal(endpoint).ConfigureAwait(false); | ||
return await endpoint.GetResponse(responseMessage).ConfigureAwait(false); | ||
} | ||
|
||
public virtual async Task<HttpResponseMessage> RunEndpointInternal(ApiEndpoint endpoint) | ||
{ | ||
var request = CreateRequest(endpoint); | ||
|
||
var response = await _nativeHttpClient.SendRequest( | ||
request, endpoint.CancellationToken ?? default).ConfigureAwait(false); | ||
|
||
await endpoint.ValidateResponse(response).ConfigureAwait(false); | ||
|
||
return response; | ||
} | ||
|
||
private HttpRequestMessage CreateRequest(ApiEndpoint endpoint) | ||
{ | ||
var request = endpoint.CreateRequest( | ||
GetBaseUri()); | ||
AddHeaders(request.Headers); | ||
return request; | ||
} | ||
|
||
public virtual Uri? GetBaseUri() => default; | ||
|
||
protected virtual void AddHeaders(HttpRequestHeaders headers) | ||
{ | ||
} | ||
} |
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,7 @@ | ||
namespace Arbus.Network; | ||
|
||
public interface IHttpClientContext | ||
{ | ||
Task RunEndpoint(ApiEndpoint endpoint); | ||
Task<TResponse> RunEndpoint<TResponse>(ApiEndpoint<TResponse> endpoint); | ||
} |
2 changes: 1 addition & 1 deletion
2
...Network/Abstractions/INativeHttpClient.cs → src/Arbus.Network/INativeHttpClient.cs
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Arbus.Network.Abstractions; | ||
namespace Arbus.Network; | ||
|
||
public interface INativeHttpClient | ||
{ | ||
|
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,7 @@ | ||
namespace Arbus.Network; | ||
|
||
public interface INetworkManager | ||
{ | ||
bool IsNetworkAvailable { get; } | ||
event EventHandler<bool>? NetworkAvailabilityChanged; | ||
} |
Oops, something went wrong.