-
-
Notifications
You must be signed in to change notification settings - Fork 285
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
fix BB-672: rewriting promises using async await in .routes/entity folder #1058
base: master
Are you sure you want to change the base?
Conversation
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.
Thanks for the work !
There's a few tricky cases in there, and by god I know they are hard to read ad reason through!
I left a bunch of comments, some of which will need to be applied to all the files (variable naming, utility function, etc.)
Do let me know if something is unclear or if you have questions.
Oh my, there are some rookie mistakes on my side. thank you for pointing them out |
Like I said, reading these promise chains and figure out what they do and when is a real pain in the ass ! |
I Renamed some variables , and I also took another look at the entity.tsx file. I found some more potential improvements in terms of rewriting the logic to remove promise chains. Although I attempted to rewrite the promises in a new syntax without altering the actual logic of the code, I still have my doubts about entity.tsx specially in -> L745 to L817. |
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 had these pending comments on the PR. I will need to do another review next week, I'm finishing up for this week as we speak.
In the meantime the comments below should apply
yup I thought so , working on this PR was little confusing for me back then and surely I made some rookie mistakes here ✅✅ PS: I will be manually checking this PR, one more time after latest changes tonight |
applying suggestions Co-authored-by: Monkey Do <[email protected]>
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.
Looking much better, thanks for having a look.
Just one remaining subtlety below, after that I think it's ready to merge.
src/server/routes/entity/entity.tsx
Outdated
try { | ||
res.send(entityDelete); | ||
search.deleteEntity(entityDelete); | ||
return entityDelete; | ||
} | ||
catch (err) { | ||
log.error(err); | ||
return error.sendErrorAsJSON(res, err); | ||
} |
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.
Here there is a small subtlety which is that previously search.deleteEntity was called after the main entityDeletePromise succeeded, in such a way that an error thrown in search.deleteEntity was not sent back to the user.
Since we are now awaiting the promise further up, we don't need this try-catch block for returning the response (res.send) anymore, but we do need one for separately catching search indexing errors like so:
try { | |
res.send(entityDelete); | |
search.deleteEntity(entityDelete); | |
return entityDelete; | |
} | |
catch (err) { | |
log.error(err); | |
return error.sendErrorAsJSON(res, err); | |
} | |
res.send(entityDelete); | |
try { | |
search.deleteEntity(entityDelete); | |
} | |
catch (err) { | |
log.error(err); | |
} | |
return entityDelete; |
However, we might need to wrap all the code from const entityDelete = await ...
onwards into another top-level try-catch block, and in the catch block use that return error.sendErrorAsJSON(res, err);
.
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.
done 👍
(〃 ̄︶ ̄)人( ̄︶ ̄〃)
I have tested this PR manually everything seems to work right as far as I checked 👍 |
Problem
BB-672Solution
This pull request finishes the remaining tasks from PR-980. I began everything again to better understand the solution for myself.
Areas of Impact
src/server/routes/entity