mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-04 02:03:14 +00:00
fix: classify duplicate vendor conflicts from parsed body (#149)
Co-authored-by: Codex Review Integration <codex-review@local.invalid>
This commit is contained in:
parent
7ec522e8ea
commit
7fdef2a46a
2 changed files with 36 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue