-
Notifications
You must be signed in to change notification settings - Fork 11
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
♻️(frontend) improve handleAIError #378
Conversation
bfbf295
to
3c98c65
Compare
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.
No blocking things, LGTM ✅
|
||
useEffect(() => { | ||
const languages = useMemo(() => { |
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.
No point in doing a useMemo here because it is not a heavy processing
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.
It is still doing a sorting on a dict of 100 elements.
const handleAIError = (error: unknown) => { | ||
if (isAPIError(error)) { | ||
if (error.status === 429) { | ||
toast( | ||
t('Too many requests. Please wait 60 seconds.'), | ||
VariantType.ERROR, | ||
); | ||
|
||
return; | ||
} | ||
} | ||
|
||
toast(t('AI seems busy! Please try again.'), VariantType.ERROR); | ||
console.error(error); | ||
}, | ||
[toast, t], | ||
); | ||
toast(t('AI seems busy! Please try again.'), VariantType.ERROR); | ||
console.error(error); | ||
}; | ||
|
||
return handleAIError; | ||
}; |
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.
Do you authorize consoles.error
?
You can simplify this hook :
const useHandleAIError = () => {
const { toast } = useToastProvider();
const { t } = useTranslation();
return (error: unknown) => {
if (isAPIError(error) && error.status === 429) {
toast(t('Too many requests. Please wait 60 seconds.'), VariantType.ERROR);
return;
}
toast(t('AI seems busy! Please try again.'), VariantType.ERROR);
};
};
if (!responseAI) { | ||
return; | ||
} |
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.
I'm not a big fan of this generic way. I would explain more because Depending on the type, it can only be a string and never undefined or null. So I would try a string
if (responseAI === '' ) {
return;
}
75c87bd
to
306549c
Compare
To display the throttle error messages, we are doing a condition on the error message that we get from the backend. It is error prone because the backend error message are internationalized. This commit fixes this issue. It DRY the component as well.
Fix a flaky tests on the e2e test: - "it renders correctly when we switch from one doc to another" - "it saves the doc when we change pages"
306549c
to
fde6283
Compare
Purpose
To display the throttle error messages, we are doing a condition on the error message that we get from the backend.
It is error prone because the backend error message are internationalized.
It fixes partially this issue: #373