Skip to content

Commit 0d00689

Browse files
committed
Output the content-length value in the error message, when we know it
1 parent 67d83d5 commit 0d00689

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/routes/publish.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ export function publishRoutes() {
5555
if (expectedLength !== undefined && expectedLength > MAX_BODY_LENGTH) {
5656
log.verbose(
5757
'length-header-check',
58-
'The length specified in the header Content-Length is too big.'
58+
`The length specified in the header Content-Length (${expectedLength}) is too big.`
5959
);
60-
throw new PayloadTooLargeError(MAX_BODY_LENGTH);
60+
throw new PayloadTooLargeError(MAX_BODY_LENGTH, expectedLength);
6161
}
6262

6363
const profileToken = await generateTokenForProfile();

src/utils/errors.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ export class PayloadTooLargeError extends Error {
2727
status = 413;
2828
expose = true;
2929

30-
constructor(maxPayloadSize: number) {
31-
super(
32-
`The length is bigger than the configured maximum ${maxPayloadSize}.`
33-
);
30+
constructor(maxPayloadSize: number, receivedPayloadSize?: number) {
31+
const message = receivedPayloadSize
32+
? `The received length ${receivedPayloadSize} is bigger than the configured maximum ${maxPayloadSize}.`
33+
: `The length is bigger than the configured maximum ${maxPayloadSize}.`;
34+
super(message);
3435
}
3536
}

test/api/publish.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ describe('publishing endpoints', () => {
127127
const req = getPreconfiguredRequest();
128128
await req
129129
.set('Content-Length', String(1024 * 1024 * 1024))
130-
.expect(413, /The length is bigger than the configured maximum/);
130+
.expect(
131+
413,
132+
/The received length \d+ is bigger than the configured maximum/
133+
);
131134
expect(process.stdout.write).toHaveBeenCalledWith(
132135
expect.stringContaining('server_error')
133136
);

0 commit comments

Comments
 (0)