mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
refactor(http): change error thrown in ServerSentEventStream
to SyntaxError
(#5135)
BREAKING(http): change error thrown in `ServerSentEventStream` to `SyntaxError`
This commit is contained in:
parent
df8cebcd74
commit
fa330f69c3
@ -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`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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",
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user