Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(tiktok-ads): retry TikTok internal service error 51002 (#82513)

Tom Owersf3b6b070b58a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/tiktok_ads/test/test_tiktok_ads_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/tiktok_ads/test/test_tiktok_ads_source.py
index 4fbb142605bd..50dbf0e3c20b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/tiktok_ads/test/test_tiktok_ads_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/tiktok_ads/test/test_tiktok_ads_source.py
@@ -123,6 +123,9 @@ class TestTikTokAdsSource:
("system_error", 50000, "System error"),
("rate_limited", 40100, "Requests made too frequently"),
("maintenance", 60001, "The system is in maintenance"),
+ # Internal service error TikTok itself asks callers to retry — must not raise the
+ # non-retryable ValueError the else-branch raises for unclassified codes.
+ ("internal_service_error", 51002, "Internal service error. Please retry later."),
]
)
def test_retryable_paginator_error_matches_get_retryable_errors(self, name, api_code, message):
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/tiktok_ads/utils.py b/products/warehouse_sources/backend/temporal/data_imports/sources/tiktok_ads/utils.py
index a02b980f2104..cf2e2d3c476d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/tiktok_ads/utils.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/tiktok_ads/utils.py
@@ -478,6 +478,7 @@ class TikTokAdsPaginator(BasePaginator):
50000, # System error
50002, # Error processing request on TikTok side. Please see error message for details.
51001, # Internal service timeout. Transient TikTok-side error; safe to retry.
+ 51002, # Internal service error. Transient TikTok-side error; TikTok's own message asks to retry later.
51039, # Internal service timeout. Transient TikTok-side error; safe to retry.
51305, # Satellite service error
60001, # The system is in maintenance.