Skip to content

Commit

Permalink
Remove example code from fetch.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwam committed Aug 17, 2020
1 parent f0f6120 commit 506bf8d
Showing 1 changed file with 0 additions and 30 deletions.
30 changes: 0 additions & 30 deletions src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,6 @@ export interface FetchEventSourceInit extends RequestInit {
fetch?: typeof fetch;
}

class RetriableError extends Error { }
class FatalError extends Error { }

fetchEventSource('/api/sse', {
async onopen(response) {
response.ok
if (response.status === 429) {
throw new RetriableError();
}
},
onmessage(msg) {
if (msg.event === 'FatalError') {
throw new FatalError(msg.data);
}
},
onclose() {
// if the server closes the connection unexpectedly, retry:
throw new RetriableError();
},
onerror(err) {
if (err instanceof FatalError) {
throw err; // rethrow to stop the operation
} else {
// do nothing to automatically retry. You can also return
// a specific retry interval instead.
}
}
});

export function fetchEventSource(input: RequestInfo, {
signal: inputSignal,
headers: inputHeaders,
Expand Down Expand Up @@ -158,7 +129,6 @@ export function fetchEventSource(input: RequestInfo, {

await parseResponse(response);

// if the event stream closes
onclose?.();
dispose();
resolve();
Expand Down

0 comments on commit 506bf8d

Please sign in to comment.