refactor(http): change error thrown in ServerSentEventStream to SyntaxError (#5135)

BREAKING(http): change error thrown in `ServerSentEventStream` to `SyntaxError`
This commit is contained in:
Asher Gomez 2024-06-25 20:27:34 +10:00 committed by GitHub
parent df8cebcd74
commit fa330f69c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 10 deletions

View File

@ -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`);
}
}

View File

@ -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",
);
});