mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-21 05:09:18 +00:00
improvement: translated all backend errors messages
This commit is contained in:
@@ -23,7 +23,7 @@ export const RefreshTokenService = async (token: string): Promise<Response> => {
|
||||
try {
|
||||
decoded = verify(token, authConfig.refreshSecret);
|
||||
} catch (err) {
|
||||
throw new AppError("Session expire. Please login.", 401);
|
||||
throw new AppError("ERR_SESSION_EXPIRED", 401);
|
||||
}
|
||||
|
||||
const { id, tokenVersion } = decoded as RefreshTokenPayload;
|
||||
@@ -31,7 +31,7 @@ export const RefreshTokenService = async (token: string): Promise<Response> => {
|
||||
const user = await ShowUserService(id);
|
||||
|
||||
if (user.tokenVersion !== tokenVersion) {
|
||||
throw new AppError("Session revoked. Please login.", 401);
|
||||
throw new AppError("ERR_SESSION_EXPIRED", 401);
|
||||
}
|
||||
|
||||
const newToken = createAccessToken(user);
|
||||
|
||||
@@ -25,7 +25,7 @@ const CreateContactService = async ({
|
||||
});
|
||||
|
||||
if (numberExists) {
|
||||
throw new AppError("A contact with this number already exists.");
|
||||
throw new AppError("ERR_DUPLICATED_CONTACT");
|
||||
}
|
||||
|
||||
const contact = await Contact.create(
|
||||
|
||||
@@ -7,7 +7,7 @@ const DeleteContactService = async (id: string): Promise<void> => {
|
||||
});
|
||||
|
||||
if (!contact) {
|
||||
throw new AppError("No contact found with this ID.", 404);
|
||||
throw new AppError("ERR_NO_CONTACT_FOUND", 404);
|
||||
}
|
||||
|
||||
await contact.destroy();
|
||||
|
||||
@@ -5,7 +5,7 @@ const ShowContactService = async (id: string | number): Promise<Contact> => {
|
||||
const contact = await Contact.findByPk(id, { include: ["extraInfo"] });
|
||||
|
||||
if (!contact) {
|
||||
throw new AppError("No contact found with this ID.", 404);
|
||||
throw new AppError("ERR_NO_CONTACT_FOUND", 404);
|
||||
}
|
||||
|
||||
return contact;
|
||||
|
||||
@@ -32,7 +32,7 @@ const UpdateContactService = async ({
|
||||
});
|
||||
|
||||
if (!contact) {
|
||||
throw new AppError("No contact found with this ID.", 404);
|
||||
throw new AppError("ERR_NO_CONTACT_FOUND", 404);
|
||||
}
|
||||
|
||||
if (extraInfo) {
|
||||
|
||||
@@ -22,7 +22,7 @@ const CreateMessageService = async ({
|
||||
const ticket = await ShowTicketService(messageData.ticketId);
|
||||
|
||||
if (!ticket) {
|
||||
throw new AppError("No ticket found with this ID", 404);
|
||||
throw new AppError("ERR_NO_TICKET_FOUND", 404);
|
||||
}
|
||||
|
||||
await Message.upsert(messageData);
|
||||
@@ -32,7 +32,7 @@ const CreateMessageService = async ({
|
||||
});
|
||||
|
||||
if (!message) {
|
||||
throw new AppError("Error while creating message on database.", 501);
|
||||
throw new AppError("ERR_CREATING_MESSAGE", 501);
|
||||
}
|
||||
|
||||
return message;
|
||||
|
||||
@@ -25,7 +25,7 @@ const ListMessagesService = async ({
|
||||
const ticket = await ShowTicketService(ticketId);
|
||||
|
||||
if (!ticket) {
|
||||
throw new AppError("No ticket found with this ID", 404);
|
||||
throw new AppError("ERR_NO_TICKET_FOUND", 404);
|
||||
}
|
||||
|
||||
const whereCondition = {
|
||||
|
||||
@@ -15,7 +15,7 @@ const UpdateSettingService = async ({
|
||||
});
|
||||
|
||||
if (!setting) {
|
||||
throw new AppError("No setting found with this ID.", 404);
|
||||
throw new AppError("ERR_NO_SETTING_FOUND", 404);
|
||||
}
|
||||
|
||||
await setting.update({ value });
|
||||
|
||||
@@ -31,7 +31,7 @@ const CreateTicketService = async ({
|
||||
const ticket = await Ticket.findByPk(id, { include: ["contact"] });
|
||||
|
||||
if (!ticket) {
|
||||
throw new AppError("Error, ticket not created.");
|
||||
throw new AppError("ERR_CREATING_TICKET");
|
||||
}
|
||||
|
||||
return ticket;
|
||||
|
||||
@@ -7,7 +7,7 @@ const DeleteTicketService = async (id: string): Promise<Ticket> => {
|
||||
});
|
||||
|
||||
if (!ticket) {
|
||||
throw new AppError("No ticket found with this ID.", 404);
|
||||
throw new AppError("ERR_NO_TICKET_FOUND", 404);
|
||||
}
|
||||
|
||||
await ticket.destroy();
|
||||
|
||||
@@ -21,7 +21,7 @@ const ShowTicketService = async (id: string | number): Promise<Ticket> => {
|
||||
});
|
||||
|
||||
if (!ticket) {
|
||||
throw new AppError("No ticket found with this ID", 404);
|
||||
throw new AppError("ERR_NO_TICKET_FOUND", 404);
|
||||
}
|
||||
|
||||
return ticket;
|
||||
|
||||
@@ -38,7 +38,7 @@ const UpdateTicketService = async ({
|
||||
});
|
||||
|
||||
if (!ticket) {
|
||||
throw new AppError("No ticket found with this ID.", 404);
|
||||
throw new AppError("ERR_NO_TICKET_FOUND", 404);
|
||||
}
|
||||
|
||||
await SetTicketMessagesAsRead(ticket);
|
||||
|
||||
@@ -9,7 +9,7 @@ const DeleteUserService = async (id: string): Promise<void> => {
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new AppError("No user found with this ID.", 404);
|
||||
throw new AppError("ERR_NO_USER_FOUND", 404);
|
||||
}
|
||||
|
||||
const userOpenTickets: Ticket[] = await user.$get("tickets", {
|
||||
|
||||
@@ -7,7 +7,7 @@ const ShowUserService = async (id: string | number): Promise<User> => {
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new AppError("No user found with this ID.", 404);
|
||||
throw new AppError("ERR_NO_USER_FOUND", 404);
|
||||
}
|
||||
|
||||
return user;
|
||||
|
||||
@@ -32,7 +32,7 @@ const UpdateUserService = async ({
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new AppError("No user found with this ID.", 404);
|
||||
throw new AppError("ERR_NO_USER_FOUND", 404);
|
||||
}
|
||||
|
||||
const schema = Yup.object().shape({
|
||||
|
||||
@@ -15,11 +15,9 @@ const CheckIsValidContact = async (number: string): Promise<void> => {
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
if (err.message === "invalidNumber") {
|
||||
throw new AppError("This is not a valid whatsapp number.");
|
||||
throw new AppError("ERR_WAPP_INVALID_CONTACT");
|
||||
}
|
||||
throw new AppError(
|
||||
"Could not valid WhatsApp contact. Check connections page"
|
||||
);
|
||||
throw new AppError("ERR_WAPP_CHECK_CONTACT");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ const handlMedia = async (
|
||||
const media = await msg.downloadMedia();
|
||||
|
||||
if (!media) {
|
||||
throw new AppError("Cannot download media from whatsapp.");
|
||||
throw new AppError("ERR_WAPP_DOWNLOAD_MEDIA");
|
||||
}
|
||||
|
||||
if (!media.filename) {
|
||||
|
||||
@@ -7,7 +7,7 @@ const DeleteWhatsApprService = async (id: string): Promise<void> => {
|
||||
});
|
||||
|
||||
if (!whatsapp) {
|
||||
throw new AppError("No whatsapp found with this ID.", 404);
|
||||
throw new AppError("ERR_NO_WAPP_FOUND", 404);
|
||||
}
|
||||
|
||||
await whatsapp.destroy();
|
||||
|
||||
@@ -7,7 +7,7 @@ const ShowWhatsAppService = async (
|
||||
const whatsapp = await Whatsapp.findByPk(id);
|
||||
|
||||
if (!whatsapp) {
|
||||
throw new AppError("No whatsapp found with this conditions.", 404);
|
||||
throw new AppError("ERR_NO_WAPP_FOUND", 404);
|
||||
}
|
||||
|
||||
return whatsapp;
|
||||
|
||||
@@ -51,7 +51,7 @@ const UpdateWhatsAppService = async ({
|
||||
});
|
||||
|
||||
if (!whatsapp) {
|
||||
throw new AppError("No whatsapp found with this ID.", 404);
|
||||
throw new AppError("ERR_NO_WAPP_FOUND", 404);
|
||||
}
|
||||
|
||||
await whatsapp.update({
|
||||
|
||||
Reference in New Issue
Block a user