pcut_uwp/PCUT/Http.Core/Handlers/DeviceAuthHandler.cs

30 lines
1.1 KiB
C#
Raw Normal View History

2024-08-21 16:02:56 +00:00
using Http.Core.Contexts;
2024-10-30 10:00:07 +00:00
using Http.Core.Exceptions;
using Http.Core.Extensions;
using PCUT.Entities.ApiResponse;
2024-08-21 16:02:56 +00:00
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Http.Core.Handlers
{
public class DeviceAuthHandler : DelegatingHandler
{
2024-10-30 10:00:07 +00:00
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2024-08-21 16:02:56 +00:00
{
2024-10-30 10:00:07 +00:00
request.Headers.Add("x-device-id", UserContext.Instance.DeviceId);
request.Headers.Add("x-version-id", UserContext.Instance.AppVersion);
var response = await base.SendAsync(request, cancellationToken);
if (response.StatusCode == System.Net.HttpStatusCode.Conflict && response.Content.Headers.ContentLength > 0)
{
var content = await response.DeserializeObjectAsync<MessageResponse>(ensureSuccess: false);
throw new AppOutdatedException(content.ErrorMessage);
}
return response;
2024-08-21 16:02:56 +00:00
}
}
}