fix(email-connectors): return profile-import error early in KlaviyoAdapter.upsertSubscriber

Open Beginner friendly
#64 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
api, backend

Research direction

Read packages/email-connectors/src/adapters/klaviyo.adapter.ts, especially KlaviyoAdapter.upsertSubscriber around lines 107-136. Trace how the /profile-import/ response is handled before the optional list relationship request. Done means a failed profile import returns its error immediately without making the list request, while successful imports keep the existing behavior.

Written by the indexing model from the issue text.

Description

backend good first issue
Problem Description

In packages/email-connectors/src/adapters/klaviyo.adapter.ts (upsertSubscriber, lines 86-136), when POST /profile-import/ fails (!profileRes.ok), profileId remains undefined. When listId is provided, the method still proceeds to call POST /lists/${listId}/relationships/profiles/ with id: undefined, which fails and masks the original /profile-import/ error behind "Failed to add to Klaviyo list: ...".


Expected Behavior
  • If POST /profile-import/ returns a non-OK response (!profileRes.ok), upsertSubscriber should immediately return { success: false, error: 'Failed to create Klaviyo profile: ...' } without making a wasted second request.
  • When POST /profile-import/ succeeds (profileRes.ok), behavior remains unchanged.

Where to Look
  • packages/email-connectors/src/adapters/klaviyo.adapter.ts (upsertSubscriber, lines 107-136)

Solution / Implementation Guide
  1. Right after const profileRes = await fetch(...), check if (!profileRes.ok) first:
    if (!profileRes.ok) {
      const errText = await profileRes.text();
      return { success: false, error: `Failed to create Klaviyo profile: ${errText}` };
    }
    
  2. Parse profileId = profileJson?.data?.id, and only proceed to POST /lists/${listId}/relationships/profiles/ when listId is provided and profileRes.ok succeeded.
Dominant language
TypeScript
Stars
2
Forks
1
Avg merge
6m
Merged PRs (30d)
27

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sumamakhan761/tryinstance

All issues in sumamakhan761/tryinstance

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.