-
Notifications
You must be signed in to change notification settings - Fork 143
fix: improve error handling in message handlers #1254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for sendbird-uikit-react ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
8162306 to
f85c0a4
Compare
f85c0a4 to
5e3e0b2
Compare
HoonBaek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
|
@HoonBaek @AhyoungRyu The What the customer seems to want is to handle failures when sending messages using SDK. try {
const params = await onBeforeSendUserMessage(...);
return await sendUserMessage(params); // -> here
} catch (error) {
// Error: Receiver is blocked
eventHandlers.message.onSendMessageFailed(error);
} |
|
I also reviewed the ticket that led to this requirement, and it seems they don’t actually need error handling but rather additional processing after a file message has been successfully sent. In the onBeforeHandler, they are sending the file message separately, performing additional processing for it, and then throwing an error to cancel the actual message send operation. This error ends up being an uncaught error, which is why they are requesting a handler. This implementation is quite strange, so wouldn’t it be better to provide a handler for post-send operations instead? const params = await onBeforeSendUserMessage(...);
const message = await sendUserMessage(params);
await onAfterSendUserMessage(message, params);
return message;onAfterSendFileMessage={async (message, params) => {
if (isValidImage(params)) {
uploadImageToS3({
params,
channelId: currentChannelId.current,
messageId: message.messageId.toString(),
}).then(() => {
handleImageSentAnalytics(sbChannel, userId, env.name);
});
}
}} |
Fixes some of comments in SBISSUE-17017
Problem
Users currently need to return an empty object from
onBeforeSendFileMessagedue to type constraints. Additionally, error handling for message sending failures needs improvement to ensureeventHandlers.messagecallbacks (onSendMessageFailed, onUpdateMessageFailed, onFileUploadFailed) are properly triggered when errors occur within their correspondingonBeforehandlers (onBeforeSendUserMessage,onBeforeSendFileMessage, etc).Solution
onBeforeXXXhandlereventHandlers.messagefor:Checklist
Put an
xin the boxes that apply. You can also fill these out after creating the PR. If unsure, ask the members.This is a reminder of what we look for before merging your code.