Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TNT-48503 Expose edge response callback #39

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Source/Adobe.Target.Client/Service/OnDeviceDecisioningService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public TargetDeliveryResponse ExecuteRequest(TargetDeliveryRequest deliveryReque
var elapsedMilliseconds = (int)stopwatch.ElapsedMilliseconds;
var telemetry = deliveryRequest.GetTelemetryEntry(this.clientConfig, elapsedMilliseconds);

CleanupGeoContext(deliveryRequest);

this.SendNotifications(deliveryRequest, targetResponse, notifications, telemetry);

TargetClient.Logger?.LogDebug(targetResponse.ToString());
Expand All @@ -160,6 +162,30 @@ internal OnDeviceDecisioningEvaluation EvaluateLocalExecution(TargetDeliveryRequ
return this.decisioningEvaluator.EvaluateLocalExecution(request);
}

private static void CleanupGeoContext(TargetDeliveryRequest deliveryRequest)
{
var geo = deliveryRequest.DeliveryRequest.Context.Geo;
if (geo == null)
{
return;
}

if (string.IsNullOrWhiteSpace(geo.City))
{
geo.City = null;
}

if (string.IsNullOrWhiteSpace(geo.StateCode))
{
geo.StateCode = null;
}

if (string.IsNullOrWhiteSpace(geo.CountryCode))
{
geo.CountryCode = null;
}
}

private static string RemoveLocationHint(string tntId)
{
if (string.IsNullOrEmpty(tntId))
Expand Down
5 changes: 4 additions & 1 deletion Source/Adobe.Target.Client/Service/TargetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ internal TargetService(TargetClientConfig clientConfig)
this.clientConfig = clientConfig;
this.logger = TargetClient.Logger;
this.stickyBaseUrl = this.clientConfig.DefaultUrl;
this.deliveryApi = new DeliveryApi(this.GetDeliveryApiConfig(this.stickyBaseUrl));
this.deliveryApi = new DeliveryApi(this.GetDeliveryApiConfig(this.stickyBaseUrl))
{
ExceptionFactory = clientConfig.ExceptionFactory,
};
RetryConfiguration.RetryPolicy = clientConfig.RetryPolicy;
RetryConfiguration.AsyncRetryPolicy = clientConfig.AsyncRetryPolicy;
}
Expand Down
25 changes: 25 additions & 0 deletions Source/Adobe.Target.Client/TargetClientConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Adobe.Target.Client
using System;
using System.Net;
using System.Threading.Tasks;
using Adobe.Target.Delivery.Client;
using Adobe.Target.Delivery.Model;
using Microsoft.Extensions.Logging;
using Polly;
Expand Down Expand Up @@ -53,6 +54,7 @@ private TargetClientConfig(Builder builder)
this.OnDeviceDecisioningReady = builder.OnDeviceDecisioningReady;
this.ArtifactDownloadSucceeded = builder.ArtifactDownloadSucceeded;
this.ArtifactDownloadFailed = builder.ArtifactDownloadFailed;
this.ExceptionFactory = builder.ExceptionFactory;
this.OnDeviceEnvironment = builder.OnDeviceEnvironment;
this.OnDeviceConfigHostname = builder.OnDeviceConfigHostname;
this.OnDeviceDecisioningPollingIntSecs = builder.OnDeviceDecisioningPollingIntSecs;
Expand Down Expand Up @@ -140,6 +142,11 @@ private TargetClientConfig(Builder builder)
/// </summary>
public Action<Exception> ArtifactDownloadFailed { get; }

/// <summary>
/// Exception Factory delegate
/// </summary>
public ExceptionFactory ExceptionFactory { get; }

/// <summary>
/// OnDevice Environment
/// </summary>
Expand Down Expand Up @@ -280,6 +287,11 @@ public Builder(string client, string organizationId)
/// </summary>
internal Action<Exception> ArtifactDownloadFailed { get; private set; }

/// <summary>
/// Exception Factory delegate
/// </summary>
internal ExceptionFactory ExceptionFactory { get; private set; }

/// <summary>
/// OnDevice Environment
/// </summary>
Expand Down Expand Up @@ -452,6 +464,19 @@ public Builder SetArtifactDownloadFailed(Action<Exception> @delegate)
return this;
}

/// <summary>
/// Sets Exception Factory delegate<br/>
/// Note: this will receive all raw Delivery API responses, <see cref="IApiResponse"/>
/// Make sure to return <c>null</c> after handling any exceptions if you don't want these to be re-thrown
/// </summary>
/// <param name="factory"><see cref="ExceptionFactory"/> delegate</param>
/// <returns><see cref="Builder"/> instance</returns>
public Builder SetExceptionFactory(ExceptionFactory factory)
{
this.ExceptionFactory = factory;
return this;
}

/// <summary>
/// Sets OnDevice Environment <br/>
/// Default: "production"
Expand Down
Loading