fix: classify duplicate vendor conflicts from parsed body (#149)
Some checks are pending
Frontend checks / Build and test (push) Waiting to run
Frontend checks / governance (push) Waiting to run
Frontend checks / Visual regression (push) Waiting to run
Deploy / deploy (push) Waiting to run

Co-authored-by: Codex Review Integration <codex-review@local.invalid>
This commit is contained in:
Alexandre Brandizzi 2026-08-27 15:33:17 -03:00 • committed by GitHub
parent 7ec522e8ea
commit 7fdef2a46a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 0 deletions

View file

@ -19,6 +19,7 @@ const OPEN_WORK_ORDER_MESSAGE =
async function readConflictBody(error: unknown): Promise<unknown> {
if (!isHTTPError(error)) return undefined;
if (error.data !== undefined && error.data !== null) return error.data;
try {
return await error.response.json();
} catch {

View file

@ -137,6 +137,41 @@ describe("vendorCompanyRosterApi", () => {
);
});
it("classifies a duplicate 409 from parsed error.data when the response body is consumed", async () => {
const conflictError = new Error("HTTPError") as Error & {
__kyHTTPError: true;
data: unknown;
response: { status: number; json: () => Promise<unknown>; text: () => Promise<string> };
};
conflictError.__kyHTTPError = true;
conflictError.data = {
code: "duplicate_vendor_company_name",
message: "Another vendor company already uses that name.",
};
const consumedBody = () => {
const rejection = Promise.reject(new TypeError("Body has already been consumed"));
rejection.catch(() => {});
return rejection;
};
conflictError.response = {
status: 409,
json: () => consumedBody(),
text: () => consumedBody(),
};
apiPost.mockRejectedValueOnce(conflictError);
await expect(vendorCompanyRosterApi.create({ name: "Solo Co" })).rejects.toSatisfy(
(error: unknown) => {
if (!isVendorRosterConflictError(error)) return false;
return (
error.conflict.kind === "duplicate" &&
error.conflict.message === "Another vendor company already uses that name."
);
},
);
});
it("rethrows non-conflict errors untouched", async () => {
const generic = new Error("boom");
apiPost.mockRejectedValueOnce(generic);