Skip to content

Commit 16f0389

Browse files
refactor(audience-sdk): introduce AudienceErrorMessages catalogue
Names the message strings routed through AudienceConfig.OnError so a wording tweak touches one file and runtime emit / test assert read from the same constants. - Log.cs: adds AudienceErrorMessages with the LocalStorageReadFailed / BatchPartiallyRejected formatters and the BatchRejectedPrefix / ServerErrorWillRetryPrefix / ConsentSyncFailedWithStatus / ConsentSyncThrew entries. - HttpTransport.cs: flush onError messages route through AudienceErrorMessages. - ImmutableAudience.cs: consent-sync onError messages route through AudienceErrorMessages.
1 parent 994279f commit 16f0389

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

src/Packages/Audience/Runtime/ImmutableAudience.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ private static void SyncConsentToBackend(AudienceConfig config, ConsentLevel lev
656656
}
657657

658658
NotifyErrorCallback(onError, AudienceErrorCode.ConsentSyncFailed,
659-
$"Consent sync failed with status {(int)response.StatusCode}");
659+
AudienceErrorMessages.ConsentSyncFailedWithStatus((int)response.StatusCode));
660660
return;
661661
}
662662
}
@@ -667,7 +667,7 @@ private static void SyncConsentToBackend(AudienceConfig config, ConsentLevel lev
667667
catch (Exception ex)
668668
{
669669
NotifyErrorCallback(onError, AudienceErrorCode.ConsentSyncFailed,
670-
$"Consent sync threw: {ex.Message}");
670+
AudienceErrorMessages.ConsentSyncThrew(ex));
671671
}
672672
});
673673
}

src/Packages/Audience/Runtime/Transport/HttpTransport.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ internal async Task<bool> SendBatchAsync(CancellationToken ct = default)
8181
// Non-IOException = unrecoverable storage failure (e.g. permissions);
8282
// retry won't help. Drop the batch, report via onError.
8383
_store.Delete(batch);
84-
NotifyError(AudienceErrorCode.FlushFailed, $"Local storage read failed: {ex.Message}");
84+
NotifyError(AudienceErrorCode.FlushFailed, AudienceErrorMessages.LocalStorageReadFailed(ex));
8585
return true;
8686
}
8787

@@ -122,7 +122,7 @@ internal async Task<bool> SendBatchAsync(CancellationToken ct = default)
122122
if (rejected > 0)
123123
{
124124
NotifyError(AudienceErrorCode.ValidationRejected,
125-
$"Batch partially rejected: {rejected} of {batch.Count} events dropped");
125+
AudienceErrorMessages.BatchPartiallyRejected(rejected, batch.Count));
126126
}
127127
}
128128
else if (statusCode == (int)HttpStatusCode.TooManyRequests)
@@ -149,7 +149,7 @@ internal async Task<bool> SendBatchAsync(CancellationToken ct = default)
149149
_store.Delete(batch);
150150
ResetBackoff();
151151
NotifyError(AudienceErrorCode.ValidationRejected,
152-
FormatHttpError("Batch rejected", statusCode, rejectionBody));
152+
FormatHttpError(AudienceErrorMessages.BatchRejectedPrefix, statusCode, rejectionBody));
153153
}
154154
else
155155
{
@@ -158,7 +158,7 @@ internal async Task<bool> SendBatchAsync(CancellationToken ct = default)
158158
var serverBody = await ReadBodyForErrorAsync(response).ConfigureAwait(false);
159159
RecordFailure();
160160
NotifyError(AudienceErrorCode.FlushFailed,
161-
FormatHttpError("Server error, will retry", statusCode, serverBody));
161+
FormatHttpError(AudienceErrorMessages.ServerErrorWillRetryPrefix, statusCode, serverBody));
162162
}
163163
}
164164
catch (OperationCanceledException) when (ct.IsCancellationRequested)

src/Packages/Audience/Runtime/Utility/Log.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@ private static void Emit(string line)
4343
}
4444
}
4545

46+
// Error messages we pass to AudienceConfig.OnError.
47+
internal static class AudienceErrorMessages
48+
{
49+
internal static string LocalStorageReadFailed(Exception ex) =>
50+
$"Local storage read failed: {ex.Message}";
51+
52+
internal static string BatchPartiallyRejected(int rejected, int total) =>
53+
$"Batch partially rejected: {rejected} of {total} events dropped";
54+
55+
internal const string BatchRejectedPrefix = "Batch rejected";
56+
internal const string ServerErrorWillRetryPrefix = "Server error, will retry";
57+
58+
internal static string ConsentSyncFailedWithStatus(int statusCode) =>
59+
$"Consent sync failed with status {statusCode}";
60+
61+
internal static string ConsentSyncThrew(Exception ex) =>
62+
$"Consent sync threw: {ex.Message}";
63+
}
64+
4665
internal static class AudienceLogs
4766
{
4867
// ---- Init / config validation ----

0 commit comments

Comments
 (0)