Skip to content

Commit 00cdca7

Browse files
refactor: adjusted voip endpoints error messages (RocketChat#33515)
1 parent b97c106 commit 00cdca7

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

apps/meteor/ee/app/api-enterprise/server/voip-freeswitch.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ API.v1.addRoute(
1919
const { username, type = 'all' } = this.queryParams;
2020

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

2525
if (type === 'all') {
@@ -71,7 +71,7 @@ API.v1.addRoute(
7171

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

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

9494
if (!extension) {
95-
throw new Error('Invalid params');
95+
throw new Error('error-invalid-params');
9696
}
9797

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

120120
if (!userId) {
121-
throw new Error('Invalid params.');
121+
throw new Error('error-invalid-params');
122122
}
123123

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

129129
const { freeSwitchExtension: extension } = user;
130130

131131
if (!extension) {
132-
throw new Error('Extension not assigned.');
132+
throw new Error('error-extension-not-assigned');
133133
}
134134

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

packages/i18n/src/locales/en.i18n.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,6 +2215,11 @@
22152215
"error-contact-sent-last-message-so-cannot-place-on-hold": "You cannot place chat on-hold, when the Contact has sent the last message",
22162216
"error-unserved-rooms-cannot-be-placed-onhold": "Room cannot be placed on hold before being served",
22172217
"error-timeout": "The request has timed out",
2218+
"error-loading-extension-list": "Failed to load extension list",
2219+
"error-registration-not-found": "Registration information not found",
2220+
"error-extension-not-available": "Extension not available",
2221+
"error-user-not-found": "User not found",
2222+
"error-extension-not-assigned": "Extension not assigned",
22182223
"Workspace_exceeded_MAC_limit_disclaimer": "The workspace has exceeded the monthly limit of active contacts. Talk to your workspace admin to address this issue.",
22192224
"You_do_not_have_permission_to_do_this": "You do not have permission to do this",
22202225
"You_do_not_have_permission_to_execute_this_command": "You do not have enough permissions to execute command: `/{{command}}`",
@@ -4460,7 +4465,6 @@
44604465
"Registration_status": "Registration status",
44614466
"Registration_Succeeded": "Registration Succeeded",
44624467
"Registration_via_Admin": "Registration via Admin",
4463-
"Registration_information_not_found": "Registration information not found",
44644468
"Regular_Expressions": "Regular Expressions",
44654469
"Reject_call": "Reject call",
44664470
"Release": "Release",
@@ -5729,7 +5733,6 @@
57295733
"User_uploaded_a_file_to_you": "<strong>{{username}}</strong> sent you a file",
57305734
"User_uploaded_file": "Uploaded a file",
57315735
"User_uploaded_image": "Uploaded an image",
5732-
"User_extension_not_found": "User extension not found",
57335736
"user-generate-access-token": "User Generate Access Token",
57345737
"user-generate-access-token_description": "Permission for users to generate access tokens",
57355738
"UserData_EnableDownload": "Enable User Data Download",

packages/i18n/src/locales/pt-BR.i18n.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,11 @@
18441844
"error-you-are-last-owner": "Você é o último proprietário da sala. Defina um novo proprietário antes de sair.",
18451845
"error-cannot-place-chat-on-hold": "Você não pode colocar a conversa em espera",
18461846
"error-timeout": "A solicitação atingiu o tempo limite",
1847+
"error-loading-extension-list": "Falha ao carregar a lista de extensões",
1848+
"error-registration-not-found": "Informações de registro não encontradas",
1849+
"error-extension-not-available": "Extensão não disponível",
1850+
"error-user-not-found": "Usuário não encontrado",
1851+
"error-extension-not-assigned": "Extensão não atribuida",
18471852
"Errors_and_Warnings": "Erros e avisos",
18481853
"Esc_to": "Esc para",
18491854
"Estimated_wait_time": "Tempo estimado de espera (tempo em minutos)",
@@ -3564,7 +3569,6 @@
35643569
"Registration": "Registro",
35653570
"Registration_Succeeded": "Registrado com sucesso",
35663571
"Registration_via_Admin": "Registro via admin",
3567-
"Registration_information_not_found": "Informações de registro não encontradas",
35683572
"Regular_Expressions": "Expressões regulares",
35693573
"Reject_call": "Rejeitar chamada",
35703574
"Release": "Versão",
@@ -4607,7 +4611,6 @@
46074611
"User_uploaded_a_file_to_you": "<strong>{{username}}</strong> enviou um arquivo para você",
46084612
"User_uploaded_file": "Carregou um arquivo",
46094613
"User_uploaded_image": "Carregou uma imagem",
4610-
"User_extension_not_found": "Extensão do usuário não encontrada",
46114614
"user-generate-access-token": "Usuário pode gerar token de acesso",
46124615
"user-generate-access-token_description": "Permissão para usuários gerarem tokens de acesso",
46134616
"UserData_EnableDownload": "Ativar o download de dados do usuário",

packages/i18n/src/locales/se.i18n.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4465,7 +4465,6 @@
44654465
"Registration_status": "Registration status",
44664466
"Registration_Succeeded": "Registration Succeeded",
44674467
"Registration_via_Admin": "Registration via Admin",
4468-
"Registration_information_not_found": "Registration information not found",
44694468
"Regular_Expressions": "Regular Expressions",
44704469
"Reject_call": "Reject call",
44714470
"Release": "Release",
@@ -5734,7 +5733,6 @@
57345733
"User_uploaded_a_file_to_you": "<strong>{{username}}</strong> sent you a file",
57355734
"User_uploaded_file": "Uploaded a file",
57365735
"User_uploaded_image": "Uploaded an image",
5737-
"User_extension_not_found": "User extension not found",
57385736
"user-generate-access-token": "User Generate Access Token",
57395737
"user-generate-access-token_description": "Permission for users to generate access tokens",
57405738
"UserData_EnableDownload": "Enable User Data Download",

packages/ui-voip/src/hooks/useVoipClient.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useUser, useSetting, useEndpoint } from '@rocket.chat/ui-contexts';
1+
import { useUser, useEndpoint, useSetting } from '@rocket.chat/ui-contexts';
22
import { useQuery } from '@tanstack/react-query';
33
import { useEffect, useRef } from 'react';
44

@@ -31,30 +31,26 @@ export const useVoipClient = ({ autoRegister = true }: VoipClientParams): VoipCl
3131
}
3232

3333
if (!userId) {
34-
throw Error('User_not_found');
34+
throw Error('error-user-not-found');
3535
}
3636

3737
const registrationInfo = await getRegistrationInfo({ userId })
3838
.then((registration) => {
3939
if (!registration) {
40-
throw Error();
40+
throw Error('error-registration-not-found');
4141
}
4242

4343
return registration;
4444
})
45-
.catch(() => {
46-
throw Error('Registration_information_not_found');
45+
.catch((e) => {
46+
throw Error(e.error || 'error-registration-not-found');
4747
});
4848

4949
const {
5050
extension: { extension },
5151
credentials: { websocketPath, password },
5252
} = registrationInfo;
5353

54-
if (!extension) {
55-
throw Error('User_extension_not_found');
56-
}
57-
5854
const config = {
5955
iceServers,
6056
authUserName: extension,

0 commit comments

Comments
 (0)