Skip to content

Commit

Permalink
chore: improve error handling for inbound calls authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
psanders committed Dec 28, 2024
1 parent 57ba7e6 commit 7d0c990
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions mods/apiserver/src/voice/VoiceClientImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,31 @@ class VoiceClientImpl implements VoiceClient {
}

async connect() {
// TODO: We should improve the error handling here. As it is now,
// it always returns true or throws an error we should return a boolean and throw an error only if the
// connection is not possible or other critical error
if (AUTHZ_SERVICE_ENABLED) {
const { sessionRef: channelId } = this.config;
const { ari } = this;

try {
const authz = new AuthzClient(
`${AUTHZ_SERVICE_HOST}:${AUTHZ_SERVICE_PORT}`
);
await authz.checkSessionAuthorized({
const authorized = await authz.checkSessionAuthorized({
accessKeyId: this.config.accessKeyId
});
} catch (e) {
const { sessionRef: channelId } = this.config;
const { ari } = this;

logger.verbose("rejected unauthorized session", { channelId });
if (!authorized) {
logger.verbose("rejected unauthorized session", { channelId });

await ari.channels.answer({ channelId });
await ari.channels.play({ channelId, media: "sound:unavailable" });
await new Promise((resolve) => setTimeout(resolve, 2000));
await ari.channels.hangup({ channelId });
return;
}
} catch (e) {
logger.error("authz service error", e);

// TODO: Play a different sound
await ari.channels.answer({ channelId });
await ari.channels.play({ channelId, media: "sound:unavailable" });
await new Promise((resolve) => setTimeout(resolve, 2000));
Expand Down

0 comments on commit 7d0c990

Please sign in to comment.