Skip to content

Commit 813ff8a

Browse files
authored
chore(util-body-length): throw Error if body length can't be computed (#3401)
1 parent 88f8cc2 commit 813ff8a

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

packages/util-body-length-browser/src/calculateBodyLength.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,10 @@ describe(calculateBodyLength.name, () => {
3333
};
3434
expect(calculateBodyLength(mockFileObject)).toEqual(mockFileObject.size);
3535
});
36+
37+
it.each([true, 1, {}, []])("throws error if Body Length computation fails for: %s", (body) => {
38+
expect(() => {
39+
expect(calculateBodyLength(body));
40+
}).toThrowError(`Body Length computation failed for ${body}`);
41+
});
3642
});

packages/util-body-length-browser/src/calculateBodyLength.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ export const calculateBodyLength = (body: any): number | undefined => {
1616
// handles browser File object
1717
return body.size;
1818
}
19+
throw new Error(`Body Length computation failed for ${body}`);
1920
};

packages/util-body-length-node/src/calculateBodyLength.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,10 @@ describe(calculateBodyLength.name, () => {
6161
}
6262
});
6363
});
64+
65+
it.each([true, 1, {}, []])("throws error if Body Length computation fails for: %s", (body) => {
66+
expect(() => {
67+
expect(calculateBodyLength(body));
68+
}).toThrowError(`Body Length computation failed for ${body}`);
69+
});
6470
});

packages/util-body-length-node/src/calculateBodyLength.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ export const calculateBodyLength = (body: any): number | undefined => {
1818
// handles fd readable streams
1919
return fstatSync(body.fd).size;
2020
}
21+
throw new Error(`Body Length computation failed for ${body}`);
2122
};

0 commit comments

Comments
 (0)