Skip to content

Commit

Permalink
fix: throw if EventSource is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Oct 1, 2024
1 parent 81cc17e commit 1226612
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/browser/sse.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { invariant } from 'outvariant'
import type { ResponseResolver } from '~/core/handlers/RequestHandler'
import {
HttpHandler,
Expand Down Expand Up @@ -39,6 +40,12 @@ export const sse: ServerSentEventRequestHandler = (path, resolver) => {

class ServerSentEventHandler extends HttpHandler {
constructor(path: Path, resolver: ServerSentEventResolver<any>) {
invariant(
typeof EventSource !== 'undefined',
'Failed to construct a Server-Sent Event handler for path "%s": your environment does not support the EventSource API',
path,
)

super('GET', path, (info) => {
const stream = new ReadableStream({
start(controller) {
Expand Down

0 comments on commit 1226612

Please sign in to comment.