Renamed SharedSerializationContext to SerializationContext. Added error handling and no build cache functionality
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using Moonlight.Api.Http.Services.ContainerHelper;
|
||||
using Moonlight.Api.Http.Services.ContainerHelper.Requests;
|
||||
@@ -32,11 +33,22 @@ public class ContainerHelperService
|
||||
}
|
||||
}
|
||||
|
||||
public async IAsyncEnumerable<RebuildEventDto> RebuildAsync()
|
||||
public async IAsyncEnumerable<RebuildEventDto> RebuildAsync(bool noBuildCache)
|
||||
{
|
||||
var client = HttpClientFactory.CreateClient("ContainerHelper");
|
||||
|
||||
var response = await client.GetAsync("api/rebuild", HttpCompletionOption.ResponseHeadersRead);
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, "api/rebuild");
|
||||
|
||||
request.Content = JsonContent.Create(
|
||||
new RequestRebuildDto(noBuildCache),
|
||||
null,
|
||||
SerializationContext.TunedOptions
|
||||
);
|
||||
|
||||
var response = await client.SendAsync(
|
||||
request,
|
||||
HttpCompletionOption.ResponseHeadersRead
|
||||
);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
@@ -90,15 +102,16 @@ public class ContainerHelperService
|
||||
new SetVersionDto(version),
|
||||
SerializationContext.TunedOptions
|
||||
);
|
||||
|
||||
if(response.IsSuccessStatusCode)
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
return;
|
||||
|
||||
var problemDetails = await response.Content.ReadFromJsonAsync<ProblemDetails>(SerializationContext.TunedOptions);
|
||||
|
||||
if(problemDetails == null)
|
||||
|
||||
var problemDetails =
|
||||
await response.Content.ReadFromJsonAsync<ProblemDetails>(SerializationContext.TunedOptions);
|
||||
|
||||
if (problemDetails == null)
|
||||
throw new HttpRequestException($"Failed to set version: {response.ReasonPhrase}");
|
||||
|
||||
|
||||
throw new HttpRequestException($"Failed to set version: {problemDetails.Detail ?? problemDetails.Title}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user