Skip to content

Commit

Permalink
review: wrap in try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
Romej committed Jun 4, 2024
1 parent 79aacd4 commit 25d565a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/simple/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,22 @@ export class Auth {
}

async initiateIdpAuthentication(domain: string, redirectUrl: string): Promise<{ location: string, saml_session_id: string }> {
const response = await getApiClient().auth.initiateIdpAuthentication(domain, redirectUrl);
try {
const response = await getApiClient().auth.initiateIdpAuthentication(domain, redirectUrl);

if (!response.ok) {
if (response.status === 404) {
throw new NoSamlRouteError('No route found for saml sso');
}

if (!response.ok) {
if (response.status === 404) {
throw new NoSamlRouteError('No route found for saml sso');
const error = await response.json();
throw new Error(error.message || error.reason);
}

const error = await response.json();
throw new Error(error.message || error.reason);
return response.json();
} catch (e: any) {
throw new Error(e.message);
}

return response.json();
}

async logInViaRefreshToken(refreshToken: string): Promise<Session | null> {
Expand Down

0 comments on commit 25d565a

Please sign in to comment.