track/src/SJZY.Track.Application/Track2InterfaceRelay/Track2InterfaceRelayHttpMessageHandler.cs
xiaolipro d12ef6d350 opt:异常友好提示
change:调整redis缓存过期时间
2024-09-27 16:59:14 +08:00

37 lines
1.4 KiB
C#

using Microsoft.Extensions.Options;
using SJZY.InterfaceRelay.Application.Contracts;
using Volo.Abp.DependencyInjection;
namespace SJZY.Track.Application.Track2InterfaceRelay;
public class Track2InterfaceRelayHttpMessageHandler : DelegatingHandler, ITransientDependency
{
private readonly Track2InterfaceRelayOptions _options;
public Track2InterfaceRelayHttpMessageHandler(IOptionsMonitor<Track2InterfaceRelayOptions> options)
{
_options = options.CurrentValue;
}
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
CancellationToken cancellationToken)
{
if (Track2InterfaceRelaySubSystemContext.Current == null)
{
throw new BusinessException(message: $"请在{nameof(Track2InterfaceRelaySubSystemContext)}中调用接口通");
}
var subSystemCode = Track2InterfaceRelaySubSystemContext.Current.SubSystemCode;
var config = _options.GetOrDefault(subSystemCode);
if (config == null)
{
throw new BusinessException(message: $"子系统{subSystemCode}未在轨迹中台配置,请联系管理员");
}
request.Headers.TryAddWithoutValidation(nameof(InterfaceForwardOptions.AppKey), config.AppKey);
request.Headers.TryAddWithoutValidation(nameof(InterfaceForwardOptions.AppSecret), config.AppSecret);
return await base.SendAsync(request, cancellationToken);
}
}