diff --git a/http/server_sent_event_stream.ts b/http/server_sent_event_stream.ts index 0a43efcf2..31080e8fd 100644 --- a/http/server_sent_event_stream.ts +++ b/http/server_sent_event_stream.ts @@ -24,7 +24,7 @@ export interface ServerSentEventMessage { function assertHasNoNewline(value: string, varName: string) { if (value.match(NEWLINE_REGEXP) !== null) { - throw new RangeError(`${varName} cannot contain a newline`); + throw new SyntaxError(`${varName} cannot contain a newline`); } } diff --git a/http/server_sent_event_stream_test.ts b/http/server_sent_event_stream_test.ts index 0dec098ec..f252b2445 100644 --- a/http/server_sent_event_stream_test.ts +++ b/http/server_sent_event_stream_test.ts @@ -62,57 +62,57 @@ Deno.test("ServerSentEventStream throws if single-line fields contain a newline" // Comment await assertRejects( async () => await createStream([{ comment: "a\n" }]).getReader().read(), - RangeError, + SyntaxError, "`message.comment` cannot contain a newline", ); await assertRejects( async () => await createStream([{ comment: "a\r" }]).getReader().read(), - RangeError, + SyntaxError, "`message.comment` cannot contain a newline", ); await assertRejects( async () => await createStream([{ comment: "a\n\r" }]).getReader().read(), - RangeError, + SyntaxError, "`message.comment` cannot contain a newline", ); // Event await assertRejects( async () => await createStream([{ event: "a\n" }]).getReader().read(), - RangeError, + SyntaxError, "`message.event` cannot contain a newline", ); await assertRejects( async () => await createStream([{ event: "a\r" }]).getReader().read(), - RangeError, + SyntaxError, "`message.event` cannot contain a newline", ); await assertRejects( async () => await createStream([{ event: "a\n\r" }]).getReader().read(), - RangeError, + SyntaxError, "`message.event` cannot contain a newline", ); // ID await assertRejects( async () => await createStream([{ id: "a\n" }]).getReader().read(), - RangeError, + SyntaxError, "`message.id` cannot contain a newline", ); await assertRejects( async () => await createStream([{ id: "a\r" }]).getReader().read(), - RangeError, + SyntaxError, "`message.id` cannot contain a newline", ); await assertRejects( async () => await createStream([{ id: "a\n\r" }]).getReader().read(), - RangeError, + SyntaxError, "`message.id` cannot contain a newline", ); });