Skip to content

Commit 9d4ba59

Browse files
authored
TNT-48503 Expose edge response callback (#39)
Geo context cleanup before ODD sendNotifications
1 parent 550bd60 commit 9d4ba59

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

Source/Adobe.Target.Client/Service/OnDeviceDecisioningService.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ public TargetDeliveryResponse ExecuteRequest(TargetDeliveryRequest deliveryReque
144144
var elapsedMilliseconds = (int)stopwatch.ElapsedMilliseconds;
145145
var telemetry = deliveryRequest.GetTelemetryEntry(this.clientConfig, elapsedMilliseconds);
146146

147+
CleanupGeoContext(deliveryRequest);
148+
147149
this.SendNotifications(deliveryRequest, targetResponse, notifications, telemetry);
148150

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

165+
private static void CleanupGeoContext(TargetDeliveryRequest deliveryRequest)
166+
{
167+
var geo = deliveryRequest.DeliveryRequest.Context.Geo;
168+
if (geo == null)
169+
{
170+
return;
171+
}
172+
173+
if (string.IsNullOrWhiteSpace(geo.City))
174+
{
175+
geo.City = null;
176+
}
177+
178+
if (string.IsNullOrWhiteSpace(geo.StateCode))
179+
{
180+
geo.StateCode = null;
181+
}
182+
183+
if (string.IsNullOrWhiteSpace(geo.CountryCode))
184+
{
185+
geo.CountryCode = null;
186+
}
187+
}
188+
163189
private static string RemoveLocationHint(string tntId)
164190
{
165191
if (string.IsNullOrEmpty(tntId))

Source/Adobe.Target.Client/Service/TargetService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ internal TargetService(TargetClientConfig clientConfig)
4646
this.clientConfig = clientConfig;
4747
this.logger = TargetClient.Logger;
4848
this.stickyBaseUrl = this.clientConfig.DefaultUrl;
49-
this.deliveryApi = new DeliveryApi(this.GetDeliveryApiConfig(this.stickyBaseUrl));
49+
this.deliveryApi = new DeliveryApi(this.GetDeliveryApiConfig(this.stickyBaseUrl))
50+
{
51+
ExceptionFactory = clientConfig.ExceptionFactory,
52+
};
5053
RetryConfiguration.RetryPolicy = clientConfig.RetryPolicy;
5154
RetryConfiguration.AsyncRetryPolicy = clientConfig.AsyncRetryPolicy;
5255
}

Source/Adobe.Target.Client/TargetClientConfig.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Adobe.Target.Client
1313
using System;
1414
using System.Net;
1515
using System.Threading.Tasks;
16+
using Adobe.Target.Delivery.Client;
1617
using Adobe.Target.Delivery.Model;
1718
using Microsoft.Extensions.Logging;
1819
using Polly;
@@ -53,6 +54,7 @@ private TargetClientConfig(Builder builder)
5354
this.OnDeviceDecisioningReady = builder.OnDeviceDecisioningReady;
5455
this.ArtifactDownloadSucceeded = builder.ArtifactDownloadSucceeded;
5556
this.ArtifactDownloadFailed = builder.ArtifactDownloadFailed;
57+
this.ExceptionFactory = builder.ExceptionFactory;
5658
this.OnDeviceEnvironment = builder.OnDeviceEnvironment;
5759
this.OnDeviceConfigHostname = builder.OnDeviceConfigHostname;
5860
this.OnDeviceDecisioningPollingIntSecs = builder.OnDeviceDecisioningPollingIntSecs;
@@ -140,6 +142,11 @@ private TargetClientConfig(Builder builder)
140142
/// </summary>
141143
public Action<Exception> ArtifactDownloadFailed { get; }
142144

145+
/// <summary>
146+
/// Exception Factory delegate
147+
/// </summary>
148+
public ExceptionFactory ExceptionFactory { get; }
149+
143150
/// <summary>
144151
/// OnDevice Environment
145152
/// </summary>
@@ -280,6 +287,11 @@ public Builder(string client, string organizationId)
280287
/// </summary>
281288
internal Action<Exception> ArtifactDownloadFailed { get; private set; }
282289

290+
/// <summary>
291+
/// Exception Factory delegate
292+
/// </summary>
293+
internal ExceptionFactory ExceptionFactory { get; private set; }
294+
283295
/// <summary>
284296
/// OnDevice Environment
285297
/// </summary>
@@ -452,6 +464,19 @@ public Builder SetArtifactDownloadFailed(Action<Exception> @delegate)
452464
return this;
453465
}
454466

467+
/// <summary>
468+
/// Sets Exception Factory delegate<br/>
469+
/// Note: this will receive all raw Delivery API responses, <see cref="IApiResponse"/>
470+
/// Make sure to return <c>null</c> after handling any exceptions if you don't want these to be re-thrown
471+
/// </summary>
472+
/// <param name="factory"><see cref="ExceptionFactory"/> delegate</param>
473+
/// <returns><see cref="Builder"/> instance</returns>
474+
public Builder SetExceptionFactory(ExceptionFactory factory)
475+
{
476+
this.ExceptionFactory = factory;
477+
return this;
478+
}
479+
455480
/// <summary>
456481
/// Sets OnDevice Environment <br/>
457482
/// Default: "production"

0 commit comments

Comments
 (0)