Skip to content

Commit

Permalink
chore(util-body-length): throw Error if body length can't be computed (
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Mar 9, 2022
1 parent 88f8cc2 commit 813ff8a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ describe(calculateBodyLength.name, () => {
};
expect(calculateBodyLength(mockFileObject)).toEqual(mockFileObject.size);
});

it.each([true, 1, {}, []])("throws error if Body Length computation fails for: %s", (body) => {
expect(() => {
expect(calculateBodyLength(body));
}).toThrowError(`Body Length computation failed for ${body}`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export const calculateBodyLength = (body: any): number | undefined => {
// handles browser File object
return body.size;
}
throw new Error(`Body Length computation failed for ${body}`);
};
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ describe(calculateBodyLength.name, () => {
}
});
});

it.each([true, 1, {}, []])("throws error if Body Length computation fails for: %s", (body) => {
expect(() => {
expect(calculateBodyLength(body));
}).toThrowError(`Body Length computation failed for ${body}`);
});
});
1 change: 1 addition & 0 deletions packages/util-body-length-node/src/calculateBodyLength.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export const calculateBodyLength = (body: any): number | undefined => {
// handles fd readable streams
return fstatSync(body.fd).size;
}
throw new Error(`Body Length computation failed for ${body}`);
};

0 comments on commit 813ff8a

Please sign in to comment.