mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 03:39:29 +00:00
improvement: started translation of backend errors
This commit is contained in:
@@ -8,9 +8,7 @@ const CheckContactOpenTickets = async (contactId: number): Promise<void> => {
|
||||
});
|
||||
|
||||
if (ticket) {
|
||||
throw new AppError(
|
||||
"There's already an open or pending ticket for this contact."
|
||||
);
|
||||
throw new AppError("ERR_OTHER_OPEN_TICKET");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ const GetDefaultWhatsApp = async (): Promise<Whatsapp> => {
|
||||
});
|
||||
|
||||
if (!defaultWhatsapp) {
|
||||
throw new AppError("No default WhatsApp found. Check Connection page.");
|
||||
throw new AppError("ERR_NO_WAPP_FOUND");
|
||||
}
|
||||
|
||||
return defaultWhatsapp;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Client as Session } from "whatsapp-web.js";
|
||||
import { getWbot } from "../libs/wbot";
|
||||
import AppError from "../errors/AppError";
|
||||
import GetDefaultWhatsApp from "./GetDefaultWhatsApp";
|
||||
import Ticket from "../models/Ticket";
|
||||
|
||||
@@ -8,9 +7,6 @@ const GetTicketWbot = async (ticket: Ticket): Promise<Session> => {
|
||||
if (!ticket.whatsappId) {
|
||||
const defaultWhatsapp = await GetDefaultWhatsApp();
|
||||
|
||||
if (!defaultWhatsapp) {
|
||||
throw new AppError("No default WhatsApp found. Check Connection page.");
|
||||
}
|
||||
await ticket.$set("whatsapp", defaultWhatsapp);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,6 @@ const CreateTicketService = async ({
|
||||
}: Request): Promise<Ticket> => {
|
||||
const defaultWhatsapp = await GetDefaultWhatsApp();
|
||||
|
||||
if (!defaultWhatsapp) {
|
||||
throw new AppError("No default WhatsApp found. Check Connection page.");
|
||||
}
|
||||
|
||||
await CheckContactOpenTickets(contactId);
|
||||
|
||||
const { isGroup } = await ShowContactService(contactId);
|
||||
|
||||
@@ -25,11 +25,11 @@ const AuthUserService = async ({
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new AppError("Incorrect user/password combination.", 401);
|
||||
throw new AppError("ERR_INVALID_CREDENTIALS", 401);
|
||||
}
|
||||
|
||||
if (!(await user.checkPassword(password))) {
|
||||
throw new AppError("Incorrect user/password combination.", 401);
|
||||
throw new AppError("ERR_INVALID_CREDENTIALS", 401);
|
||||
}
|
||||
|
||||
const token = createAccessToken(user);
|
||||
|
||||
@@ -25,9 +25,7 @@ const DeleteWhatsAppMessage = async (messageId: string): Promise<Message> => {
|
||||
try {
|
||||
await messageToDelete.delete(true);
|
||||
} catch (err) {
|
||||
throw new AppError(
|
||||
"Couldn't delete message from WhatsApp. Check connections page."
|
||||
);
|
||||
throw new AppError("ERR_DELETE_WAPP_MSG");
|
||||
}
|
||||
|
||||
await message.update({ isDeleted: true });
|
||||
|
||||
@@ -31,9 +31,7 @@ const SendWhatsAppMedia = async ({
|
||||
return sentMessage;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw new AppError(
|
||||
"Could not send whatsapp message. Check connections page."
|
||||
);
|
||||
throw new AppError("ERR_SENDING_WAPP_MSG");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -24,9 +24,7 @@ const SendWhatsAppMessage = async ({
|
||||
return sentMessage;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw new AppError(
|
||||
"Could not send whatsapp message. Check connections page."
|
||||
);
|
||||
throw new AppError("ERR_SENDING_WAPP_MSG");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user