OUT-3754: correct duplicate doc number code from 6240 to 6140 - #252
Conversation
Per Intuit docs, QBO error 6140 is "Duplicate Document Number" and 6240 is "Duplicate Name Exists". isQBODuplicateDocNumberError was matching 6240, so the suffix-retry path in webhookInvoiceCreated never fired on real doc-number collisions — every one fell through to FAILED. Swap 6240 -> 6140 in the detector, the log/breadcrumb strings, JSDoc, and the docNumber unit + integration test fixtures. 6240 references that legitimately refer to Duplicate Name (customer DisplayName guard) or are generic examples are left alone. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR corrects a misidentified QBO error code in
Confidence Score: 5/5Safe to merge — the change is a targeted one-constant correction backed by the official Intuit documentation and covered by existing tests. The fix is a straightforward swap of the wrong error code for the correct one across source, comments, and tests. All six changed files are consistent, no logic is restructured, and the remaining 6240 references in the codebase are for an unrelated error (customer DisplayName collision) and are correctly untouched. Unit tests pass at 165/165. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant WH as webhookInvoiceCreated
participant RDN as resolveAvailableDocNumber
participant QBO as QBO API
participant Det as isQBODuplicateDocNumberError
WH->>RDN: pre-flight prefix query
RDN->>QBO: _findInvoicesByDocNumberPrefix
QBO-->>RDN: existing DocNumbers
RDN-->>WH: available docNumber
WH->>QBO: createInvoice(docNumber)
alt success
QBO-->>WH: Invoice created
else QBO returns error
QBO-->>WH: Error (code 6140 "Duplicate Document Number")
WH->>Det: isQBODuplicateDocNumberError(err)
Note over Det: Previously matched 6240 (wrong)<br/>Now correctly matches 6140
Det-->>WH: true
WH->>RDN: re-walk once
RDN->>QBO: _findInvoicesByDocNumberPrefix
QBO-->>RDN: updated DocNumbers
RDN-->>WH: new available docNumber
WH->>QBO: createInvoice(newDocNumber)
QBO-->>WH: Invoice created (retry succeeded)
end
Reviews (1): Last reviewed commit: "fix(OUT-3754): correct duplicate doc num..." | Re-trigger Greptile |
priosshrsth
left a comment
There was a problem hiding this comment.
@SandipBajracharya I would suggest to use QB_STATUS_CODES constant. So we can do like QB_STATUS_CODE.DUPLICATE_DOC_NUMBER, etc. and in comments instead of vague 6140, we say DUPLICATE_DOC_NUMBER, wdyt?
…stant - Extend src/constant/intuitErrorCode.ts with a named QBOErrorCodes map covering DUPLICATE_DOC_NUMBER, DUPLICATE_NAME_EXISTS, BUSINESS_VALIDATION, and ACCOUNT_SUSPENDED. Derive the existing AccountErrorCodes array from it to avoid drift. - Update isQBODuplicateDocNumberError to derive its numeric, string, and regex checks from QBOErrorCodes.DUPLICATE_DOC_NUMBER. - Reference the constant from both the unit recognizer tests and the integration test's mock 6140 fault envelope. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Number() collapses the string + number branches into one comparison since
Number('6140') === Number(6140) and unparseable inputs return NaN (never
equal to the target). Drops the redundant DUP_DOC_NUMBER_CODE_STR
constant and merges the two top-level .status / .code checks into a
single short-circuiting expression.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Nice suggestion. Thanks |
- intuitAPI.ts: swap the JSDoc example fault code from 6240 to 6140 so it doesn't conflate with QBOErrorCodes.DUPLICATE_NAME_EXISTS. - invoice.utils.ts: document that DUP_DOC_NUMBER_PATTERN relies on QBOErrorCode being a numeric literal union — no regex escaping needed today, but the comment flags the assumption for future maintainers. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
Per Intuit docs, QBO error 6140 is "Duplicate Document Number" and 6240 is "Duplicate Name Exists".
isQBODuplicateDocNumberErrorwas matching 6240, so the suffix-retry path inwebhookInvoiceCreated(OUT-3708) never fired on real doc-number collisions — every collision fell through to a FAILEDqb_sync_log.Swap 6240 → 6140 in the detector, log/breadcrumb strings, JSDoc, and the docNumber-specific tests. References to 6240 that legitimately refer to "Duplicate Name Exists" (customer DisplayName collision guard) or that just use 6240 as a generic fault-code example are left alone.
Code sites
src/app/api/quickbooks/invoice/invoice.utils.ts—isQBODuplicateDocNumberErrorsrc/app/api/quickbooks/invoice/invoice.service.ts—resolveAvailableDocNumberJSDoc + catch/retry log + breadcrumbsrc/utils/intuitAPI.ts—_findInvoicesByDocNumberPrefixJSDoc referencetest/unit/app/api/quickbooks/invoice/invoice.utils.test.tstest/unit/app/api/quickbooks/invoice/invoice.service.docNumber.test.tstest/integration/quickbooks/invoiceCreated/qboDocNumberCollision.test.tsTest plan
npx vitest run --project unit— 165/165 passing🤖 Generated with Claude Code