improvement: translated all backend errors messages

This commit is contained in:
canove
2020-10-13 22:53:05 -03:00
parent 558475f121
commit a567614c63
45 changed files with 308 additions and 120 deletions

View File

@@ -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);

View File

@@ -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(

View File

@@ -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();

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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 = {

View File

@@ -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 });

View File

@@ -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;

View File

@@ -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();

View File

@@ -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;

View File

@@ -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);

View File

@@ -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", {

View File

@@ -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;

View File

@@ -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({

View File

@@ -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");
}
};

View File

@@ -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) {

View File

@@ -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();

View File

@@ -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;

View File

@@ -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({