-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathhandleSamlError.ts
More file actions
27 lines (25 loc) · 870 Bytes
/
handleSamlError.ts
File metadata and controls
27 lines (25 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import {Octokit} from "@octokit/rest";
import {AuthenticationSession} from "vscode";
import {newSession} from "../auth/auth";
import {logDebug} from "../log";
import {getClient} from "./api";
export async function handleSamlError<T>(
session: AuthenticationSession,
request: (client: Octokit) => Promise<T>
): Promise<T> {
try {
const client = getClient(session.accessToken);
return await request(client);
} catch (error) {
if ((error as Error).message.includes("Resource protected by organization SAML enforcement.")) {
logDebug("SAML error, re-authenticating");
const session = await newSession(
"Your organization is protected by SAML enforcement. Please sign-in again to continue."
);
const client = getClient(session.accessToken);
return await request(client);
} else {
throw error;
}
}
}