Skip to content

Commit

Permalink
refactor: adjusted voip error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandernsilva committed Oct 9, 2024
1 parent 6843990 commit eead000
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
14 changes: 7 additions & 7 deletions apps/meteor/ee/app/api-enterprise/server/voip-freeswitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ API.v1.addRoute(
const { username, type = 'all' } = this.queryParams;

const extensions = await wrapExceptions(() => VoipFreeSwitch.getExtensionList()).catch(() => {
throw new Error('Failed to load extension list.');
throw new Error('error-loading-extension-list');
});

if (type === 'all') {
Expand Down Expand Up @@ -71,7 +71,7 @@ API.v1.addRoute(

const existingUser = extension && (await Users.findOneByFreeSwitchExtension(extension, { projection: { _id: 1 } }));
if (existingUser && existingUser._id !== user._id) {
throw new Error('Extension not available.');
throw new Error('error-extension-not-available');
}

if (extension && user.freeSwitchExtension === extension) {
Expand All @@ -92,7 +92,7 @@ API.v1.addRoute(
const { extension, group } = this.queryParams;

if (!extension) {
throw new Error('Invalid params');
throw new Error('error-invalid-params');
}

const extensionData = await wrapExceptions(() => VoipFreeSwitch.getExtensionDetails({ extension, group })).suppress(() => undefined);
Expand All @@ -118,23 +118,23 @@ API.v1.addRoute(
const { userId } = this.queryParams;

if (!userId) {
throw new Error('Invalid params.');
throw new Error('error-invalid-params');
}

const user = await Users.findOneById(userId, { projection: { freeSwitchExtension: 1 } });
if (!user) {
throw new Error('User not found.');
throw new Error('error-user-not-found');
}

const { freeSwitchExtension: extension } = user;

if (!extension) {
throw new Error('Extension not assigned.');
throw new Error('error-extension-not-assigned');
}

const extensionData = await wrapExceptions(() => VoipFreeSwitch.getExtensionDetails({ extension })).suppress(() => undefined);
if (!extensionData) {
return API.v1.notFound();
return API.v1.notFound('error-registration-not-found');
}
const password = await wrapExceptions(() => VoipFreeSwitch.getUserPassword(extension)).suppress(() => undefined);

Expand Down
7 changes: 5 additions & 2 deletions packages/i18n/src/locales/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,11 @@
"error-contact-sent-last-message-so-cannot-place-on-hold": "You cannot place chat on-hold, when the Contact has sent the last message",
"error-unserved-rooms-cannot-be-placed-onhold": "Room cannot be placed on hold before being served",
"error-timeout": "The request has timed out",
"error-loading-extension-list": "Failed to load extension list",
"error-registration-not-found": "Registration information not found",
"error-extension-not-available": "Extension not available",
"error-user-not-found": "User not found",
"error-extension-not-assigned": "Extension not assigned",
"Workspace_exceeded_MAC_limit_disclaimer": "The workspace has exceeded the monthly limit of active contacts. Talk to your workspace admin to address this issue.",
"You_do_not_have_permission_to_do_this": "You do not have permission to do this",
"You_do_not_have_permission_to_execute_this_command": "You do not have enough permissions to execute command: `/{{command}}`",
Expand Down Expand Up @@ -4459,7 +4464,6 @@
"Registration_status": "Registration status",
"Registration_Succeeded": "Registration Succeeded",
"Registration_via_Admin": "Registration via Admin",
"Registration_information_not_found": "Registration information not found",
"Regular_Expressions": "Regular Expressions",
"Reject_call": "Reject call",
"Release": "Release",
Expand Down Expand Up @@ -5728,7 +5732,6 @@
"User_uploaded_a_file_to_you": "<strong>{{username}}</strong> sent you a file",
"User_uploaded_file": "Uploaded a file",
"User_uploaded_image": "Uploaded an image",
"User_extension_not_found": "User extension not found",
"user-generate-access-token": "User Generate Access Token",
"user-generate-access-token_description": "Permission for users to generate access tokens",
"UserData_EnableDownload": "Enable User Data Download",
Expand Down
7 changes: 5 additions & 2 deletions packages/i18n/src/locales/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,11 @@
"error-you-are-last-owner": "Você é o último proprietário da sala. Defina um novo proprietário antes de sair.",
"error-cannot-place-chat-on-hold": "Você não pode colocar a conversa em espera",
"error-timeout": "A solicitação atingiu o tempo limite",
"error-loading-extension-list": "Falha ao carregar a lista de extensões",
"error-registration-not-found": "Informações de registro não encontradas",
"error-extension-not-available": "Extensão não disponível",
"error-user-not-found": "Usuário não encontrado",
"error-extension-not-assigned": "Extensão não atribuida",
"Errors_and_Warnings": "Erros e avisos",
"Esc_to": "Esc para",
"Estimated_wait_time": "Tempo estimado de espera (tempo em minutos)",
Expand Down Expand Up @@ -3564,7 +3569,6 @@
"Registration": "Registro",
"Registration_Succeeded": "Registrado com sucesso",
"Registration_via_Admin": "Registro via admin",
"Registration_information_not_found": "Informações de registro não encontradas",
"Regular_Expressions": "Expressões regulares",
"Reject_call": "Rejeitar chamada",
"Release": "Versão",
Expand Down Expand Up @@ -4607,7 +4611,6 @@
"User_uploaded_a_file_to_you": "<strong>{{username}}</strong> enviou um arquivo para você",
"User_uploaded_file": "Carregou um arquivo",
"User_uploaded_image": "Carregou uma imagem",
"User_extension_not_found": "Extensão do usuário não encontrada",
"user-generate-access-token": "Usuário pode gerar token de acesso",
"user-generate-access-token_description": "Permissão para usuários gerarem tokens de acesso",
"UserData_EnableDownload": "Ativar o download de dados do usuário",
Expand Down
14 changes: 5 additions & 9 deletions packages/ui-voip/src/hooks/useVoipClient.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useUser, useSetting, useEndpoint } from '@rocket.chat/ui-contexts';
import { useUser, useEndpoint, useSetting } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import { useEffect, useRef } from 'react';

Expand All @@ -14,7 +14,7 @@ type VoipClientResult = {
error: Error | null;
};

export const useVoipClient = ({ autoRegister = true }: VoipClientParams): VoipClientResult => {
export const useVoipClient = ({ autoRegister = true }: VoipClientParams = {}): VoipClientResult => {
const { _id: userId } = useUser() || {};
const isVoipEnabled = useSetting<boolean>('VoIP_TeamCollab_Enabled');
const voipClientRef = useRef<VoipClient | null>(null);
Expand All @@ -31,7 +31,7 @@ export const useVoipClient = ({ autoRegister = true }: VoipClientParams): VoipCl
}

if (!userId) {
throw Error('User_not_found');
throw Error('error-user-not-found');
}

const registrationInfo = await getRegistrationInfo({ userId })
Expand All @@ -42,19 +42,15 @@ export const useVoipClient = ({ autoRegister = true }: VoipClientParams): VoipCl

return registration;
})
.catch(() => {
throw Error('Registration_information_not_found');
.catch((e) => {
throw Error(e.error || 'error-registration-not-found');
});

const {
extension: { extension },
credentials: { websocketPath, password },
} = registrationInfo;

if (!extension) {
throw Error('User_extension_not_found');
}

const config = {
iceServers,
authUserName: extension,
Expand Down

0 comments on commit eead000

Please sign in to comment.