mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 12:49:32 +00:00
improvement: better error messages in frontend
This commit is contained in:
@@ -41,13 +41,23 @@ exports.store = async (req, res) => {
|
|||||||
const io = getIO();
|
const io = getIO();
|
||||||
const newContact = req.body;
|
const newContact = req.body;
|
||||||
|
|
||||||
const result = await wbot.isRegisteredUser(`${newContact.number}@c.us`);
|
let isValidNumber;
|
||||||
|
|
||||||
if (!result) {
|
try {
|
||||||
|
isValidNumber = await wbot.isRegisteredUser(`${newContact.number}@c.us`);
|
||||||
|
} catch (err) {
|
||||||
|
console.log("Could not check whatsapp contact. Is session details valid?");
|
||||||
|
return res.status(500).json({
|
||||||
|
error: "Could not check whatsapp contact. Check connection page.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isValidNumber) {
|
||||||
return res
|
return res
|
||||||
.status(400)
|
.status(400)
|
||||||
.json({ error: "The suplied number is not a valid Whatsapp number" });
|
.json({ error: "The suplied number is not a valid Whatsapp number" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const profilePicUrl = await wbot.getProfilePicUrl(
|
const profilePicUrl = await wbot.getProfilePicUrl(
|
||||||
`${newContact.number}@c.us`
|
`${newContact.number}@c.us`
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ exports.store = async (req, res, next) => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
if (media) {
|
if (media) {
|
||||||
const newMedia = MessageMedia.fromFilePath(req.file.path);
|
const newMedia = MessageMedia.fromFilePath(req.file.path);
|
||||||
|
|
||||||
@@ -148,9 +149,14 @@ exports.store = async (req, res, next) => {
|
|||||||
);
|
);
|
||||||
await ticket.update({ lastMessage: message.body });
|
await ticket.update({ lastMessage: message.body });
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.log(
|
||||||
|
"Could not create whatsapp message. Is session details valid? "
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sentMessage) {
|
||||||
message.id = sentMessage.id.id;
|
message.id = sentMessage.id.id;
|
||||||
|
|
||||||
const newMessage = await ticket.createMessage(message);
|
const newMessage = await ticket.createMessage(message);
|
||||||
|
|
||||||
const serialziedMessage = {
|
const serialziedMessage = {
|
||||||
@@ -172,4 +178,9 @@ exports.store = async (req, res, next) => {
|
|||||||
await setMessagesAsRead(ticket);
|
await setMessagesAsRead(ticket);
|
||||||
|
|
||||||
return res.json({ newMessage, ticket });
|
return res.json({ newMessage, ticket });
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
.status(500)
|
||||||
|
.json({ error: "Cannot sent whatsapp message. Check connection page." });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -86,7 +86,8 @@ const ContactModal = ({ open, onClose, contactId }) => {
|
|||||||
await api.post("/contacts", values);
|
await api.post("/contacts", values);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(err);
|
alert(err.response.data.error);
|
||||||
|
console.log(err);
|
||||||
}
|
}
|
||||||
handleClose();
|
handleClose();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -163,8 +163,8 @@ const MessageInput = () => {
|
|||||||
try {
|
try {
|
||||||
await api.post(`/messages/${ticketId}`, formData);
|
await api.post(`/messages/${ticketId}`, formData);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
alert(err.response.data.error);
|
||||||
console.log(err);
|
console.log(err);
|
||||||
alert(err);
|
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setMedia(mediaInitialState);
|
setMedia(mediaInitialState);
|
||||||
@@ -182,7 +182,8 @@ const MessageInput = () => {
|
|||||||
try {
|
try {
|
||||||
await api.post(`/messages/${ticketId}`, message);
|
await api.post(`/messages/${ticketId}`, message);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(err);
|
alert(err.response.data.error);
|
||||||
|
console.log(err);
|
||||||
}
|
}
|
||||||
setInputMessage("");
|
setInputMessage("");
|
||||||
setShowEmoji(false);
|
setShowEmoji(false);
|
||||||
@@ -217,20 +218,19 @@ const MessageInput = () => {
|
|||||||
}
|
}
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
const filename = `${new Date().getTime()}.mp3`;
|
const filename = `${new Date().getTime()}.mp3`;
|
||||||
console.log(blob);
|
|
||||||
formData.append("media", blob, filename);
|
formData.append("media", blob, filename);
|
||||||
formData.append("body", filename);
|
formData.append("body", filename);
|
||||||
formData.append("fromMe", true);
|
formData.append("fromMe", true);
|
||||||
try {
|
try {
|
||||||
await api.post(`/messages/${ticketId}`, formData);
|
await api.post(`/messages/${ticketId}`, formData);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
alert(err.response.data.error);
|
||||||
console.log(err);
|
console.log(err);
|
||||||
alert(err);
|
|
||||||
}
|
}
|
||||||
setRecording(false);
|
setRecording(false);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
})
|
})
|
||||||
.catch(e => console.log(e));
|
.catch(err => console.log(err));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancelAudio = () => {
|
const handleCancelAudio = () => {
|
||||||
|
|||||||
@@ -32,11 +32,7 @@ const RouteWrapper = ({ component: Component, isPrivate = false, ...rest }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isAuth && !isPrivate) {
|
if (isAuth && !isPrivate) {
|
||||||
return (
|
return <Redirect to={{ pathname: "/", state: { from: rest.location } }} />;
|
||||||
<Redirect
|
|
||||||
to={{ pathname: "/dashboard", state: { from: rest.location } }}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return <Route {...rest} component={Component} />;
|
return <Route {...rest} component={Component} />;
|
||||||
|
|||||||
Reference in New Issue
Block a user