Skip to content

fix(link): send QR code custom options as multipart/form-data#137

Merged
jaredwray merged 1 commit into
mainfrom
claude/wonderful-goodall-hvwm0l
Jun 12, 2026
Merged

fix(link): send QR code custom options as multipart/form-data#137
jaredwray merged 1 commit into
mainfrom
claude/wonderful-goodall-hvwm0l

Conversation

@jaredwray

Copy link
Copy Markdown
Contributor

Problem

Creating a QR code with custom options (title, backgroundColor, color, size, logo) failed against the Hyphen API. The previously-skipped integration test confirmed it (see #133), and I reproduced it against the live API:

Error: Fetch failed with status 400

Root cause

The QR create endpoint in apix (POST /organizations/:org/link/codes/:code/qrs) consumes multipart/form-datafastify/multipart is registered with attachFieldsToBody: true, the schema declares consumes: ['multipart/form-data'], each field is read as body[key].value, and logo is a file (isFile: true).

The SDK's createQrCode, however, sent the options as a JSON body with content-type: application/json. Schema validation expected each field to be an object ({ value }), so a JSON string like { "title": "..." } was rejected with HTTP 400.

This is why QR creation without options worked (the body serialized to {}, which passes validation) but with options always failed — exactly the reported symptom.

Fix (SDK only)

createQrCode now builds a multipart/form-data request:

  • title, backgroundColor, color, size are sent as form fields.
  • logo (a base64 string) is decoded and appended as a file upload, matching the API's isFile expectation.
  • The JSON content-type header is dropped so the multipart boundary is set automatically by fetch.
  • When no options are provided, the SDK falls back to an empty JSON body, because the API rejects an empty multipart payload with {"message":"body must be object"} — this preserves the existing default-QR behavior.

The public API is unchanged: callers still pass CreateQrCodeOptions exactly as before. No apix changes are required — the SDK simply now conforms to the existing multipart contract.

Verification

  • Re-enabled the previously skipped custom-options integration test; it now passes against the live API.
  • Added unit coverage for both the multipart (with options) and empty-JSON (no options) paths, asserting the body shape and content-type handling.
  • pnpm test: 233 passed, 100% coverage (statements/branches/functions/lines).
  • pnpm build: succeeds with no type errors.

Closes #133

https://claude.ai/code/session_01Taskt9xiXWzsGVmKPbPpnj


Generated by Claude Code

The QR create endpoint (/qrs) consumes multipart/form-data, but
createQrCode sent the personalization options (title, backgroundColor,
color, size, logo) as a JSON body. The API rejected that payload with
HTTP 400, so QR codes could only be created without custom options.

Build the request as multipart/form-data, sending each option as a form
field and the logo (base64) as a decoded file upload. When no options
are provided, fall back to an empty JSON body since the API rejects an
empty multipart payload.

Re-enables the previously skipped custom-options integration test and
adds unit coverage for both the multipart and empty-body paths.

https://claude.ai/code/session_01Taskt9xiXWzsGVmKPbPpnj
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (54f15b5) to head (6de740b).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #137   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            8         8           
  Lines          477       492   +15     
  Branches        95       101    +6     
=========================================
+ Hits           477       492   +15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jaredwray jaredwray merged commit 7a5a164 into main Jun 12, 2026
9 checks passed
@jaredwray jaredwray deleted the claude/wonderful-goodall-hvwm0l branch June 12, 2026 15:58
@jaredwray jaredwray mentioned this pull request Jun 12, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky/failing test: should create a QR code with custom options returns HTTP 400

2 participants