Skip to content

Commit

Permalink
chore: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Benmuiruri committed Feb 17, 2025
1 parent cee7190 commit 4c5aa85
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
8 changes: 0 additions & 8 deletions src/lib/authentication-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,4 @@ export class AuthError extends Error {
static CANNOT_PARSE_CHT_VERSION(chtCoreVersion: string, domain: string) {
return new AuthError(401, `Cannot parse cht core version ${chtCoreVersion} for instance "${domain}"`);
}

static assertSessionCreationError(e: unknown): never {
// @ts-expect-error
if (e?.response?.status === 401) {
throw AuthError.INVALID_CREDENTIALS();
}
throw e;
}
}
7 changes: 5 additions & 2 deletions src/lib/cht-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ export default class ChtSession {
throw AuthError.TOKEN_CREATION_FAILED(username, authInfo.domain);
}
return token;
} catch (e) {
AuthError.assertSessionCreationError(e);
} catch (e: any) {
if (e?.response?.status === 401) {
throw AuthError.INVALID_CREDENTIALS();
}
throw e;
}
}

Expand Down
1 change: 0 additions & 1 deletion test/lib/authentication.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import chai from 'chai';
import chaiExclude from 'chai-exclude';
import { mockChtSession } from '../mocks';
import Auth from '../../src/lib/authentication';
import { AuthError } from '../../src/lib/authentication-error';

chai.use(chaiExclude);
const { expect } = chai;
Expand Down

0 comments on commit 4c5aa85

Please sign in to comment.