fix(ms-bing-ads-audiences): surface real Bing API errors in createAudience#3846
Open
harsh-joshi99 wants to merge 1 commit into
Open
fix(ms-bing-ads-audiences): surface real Bing API errors in createAudience#3846harsh-joshi99 wants to merge 1 commit into
harsh-joshi99 wants to merge 1 commit into
Conversation
…ience Previously createAudience swallowed Bing Ads API failures into opaque errors: a non-2xx response (often empty/non-JSON body) escaped as an untyped error that the platform reported as a generic "500 / Bad Request" with no detail, and any PartialError other than the Terms & Conditions case fell through to "No AudienceId returned" (NO_AUDIENCE_ID), discarding Bing's actual ErrorCode/Message. Changes: - Wrap the POST /Audiences call in try/catch; on HTTPError, capture Bing's actual status and response body so the real cause is visible in logs. - Classify 5xx as RetryableError (relays status:500 downstream as transient) and other non-2xx as IntegrationError with Bing's status. - Surface every non-T&C PartialError with Bing's own ErrorCode and Message instead of collapsing into NO_AUDIENCE_ID. - Add a safe readResponseBody helper that never throws on empty/non-JSON. Adds unit tests asserting error type, status, and code for the non-2xx (400), 5xx, and unrecognized-PartialError paths. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
Improve diagnosability of createAudience failures for the Ms Bing Ads Audiences destination by surfacing Bing’s actual HTTP/PartialErrors (status/body/ErrorCode) instead of opaque generic errors.
Changes:
- Add safe(ish) error-body extraction and wrap
POST /Audiencesto rethrow typedIntegrationError/RetryableErrorwith Bing status + body. - Surface non–T&C
PartialErrorsusing Bing’sErrorCodeandMessage. - Add unit tests for non-2xx, 5xx retryable behavior, and unrecognized
PartialErrorhandling.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/destination-actions/src/destinations/ms-bing-ads-audiences/index.ts | Add HTTP error handling + PartialErrors surfacing to improve logging/observability and retry semantics. |
| packages/destination-actions/src/destinations/ms-bing-ads-audiences/tests/index.test.ts | Add unit tests covering new error paths and retryable classification. |
Comment on lines
+21
to
+30
| const readResponseBody = async (response?: Response): Promise<string> => { | ||
| if (!response) { | ||
| return '' | ||
| } | ||
| try { | ||
| return (await response.text()) ?? '' | ||
| } catch { | ||
| return '' | ||
| } | ||
| } |
Comment on lines
+131
to
+133
| const message = `Failed to create audience. Microsoft Bing Ads returned HTTP ${status ?? 'unknown'}: ${ | ||
| body || 'no response body' | ||
| }` |
Comment on lines
+120
to
+126
| await expect(testDestination.createAudience(createAudienceInput)).rejects.toThrowError( | ||
| new IntegrationError( | ||
| 'Failed to create audience: CampaignServiceDuplicateAudienceName: An audience with this name already exists.', | ||
| 'CampaignServiceDuplicateAudienceName', | ||
| 400 | ||
| ) | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
createAudienceflow for Ms Bing Ads Audiences was masking the actual cause of create failures, producing opaque errors that made customer issues (e.g. STRATCONN / legalzoom-prod) impossible to diagnose from logs.Two distinct gaps:
POST /Audiencescall had no error handling. When Bing returned a non-2xx (often an empty / non-JSON body), the request client threw a raw error that bubbled up untyped — the platform reported it as a generic500 / INTERNAL / "Bad Request"with an emptyresponseFromDestination, so Bing's real status/body was never logged.200with aPartialErrorsarray for most create failures. Only the Terms & Conditions code was handled; every other code (e.g. a duplicate audience name) fell through to the opaqueNO_AUDIENCE_IDerror, discarding Bing's actualErrorCode/Message.Changes
POST /Audiencescall in try/catch; onHTTPError, capture Bing's actual status and response body in the thrown error so the real cause is visible in logs (and the downstreamsendGXRequest-errorpayload).RetryableError(relaysstatus: 500downstream as transient); other non-2xx asIntegrationErrorcarrying Bing's status.ErrorCodeandMessageinstead of collapsing intoNO_AUDIENCE_ID.readResponseBodyhelper that never throws on empty / non-JSON bodies.Contract notes
createAudiencestill returnsAudienceResult = { externalId: string }on success — unchanged. Failures are thrown, per the framework contract.status/code/messageare exactly what external-audience-service's gxClient logs, so this directly improves the Grafana visibility for these failures.Testing
🤖 Generated with Claude Code