We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 03e583b commit 9262151Copy full SHA for 9262151
src/client/sse.ts
@@ -195,8 +195,17 @@ export class SSEClientTransport implements Transport {
195
};
196
197
const response = await fetch(this._endpoint, init);
198
-
199
if (!response.ok) {
+ if (response.status === 401 && this._authProvider) {
200
+ const result = await auth(this._authProvider, { serverUrl: this._url });
201
+ if (result !== "AUTHORIZED") {
202
+ throw new Error("Unauthorized");
203
+ }
204
+
205
+ // Purposely _not_ awaited, so we don't call onerror twice
206
+ return this.send(message);
207
208
209
const text = await response.text().catch(() => null);
210
throw new Error(
211
`Error POSTing to endpoint (HTTP ${response.status}): ${text}`,
0 commit comments