-
Notifications
You must be signed in to change notification settings - Fork 87
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
feat(v2): add clearer error messages when updating collaborators #3864
Merged
siddarth2824
merged 9 commits into
form-v2/develop
from
form-v2/feat/refactor-collab-error-messages
May 19, 2022
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dfb6291
feat: add clearer error messages when updating collaborators
fadfb1d
fix: use non-null assertion to assert optional requestEmail variable …
fd629fc
fix: add non-null check of email in request for 422 error messages
0f06cb6
fix: refactor type of error declared in func
b1143ed
fix: add return type to function
878b4ef
feat: add tests
e503a8f
feat: remove interactions for collaborator modal stories
a0e3423
fix: remove unprocessable entity error story
133fcfa
feat: update error message for bad request error
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The
!
a not a non-null assertion, it’s the logical not operator. It will convert whatever truthinessrequestEmail
represents to its oppositetrue
orfalse
, and so the resulting message will be either :or
which is not what we want 😅 .
If
requestEmail
is always defined on 422 errors, we can make it clear with a cast:errorMessage =
${requestEmail as string} is not part of a whitelisted agency
If
requestEmail
may beundefined
, we’d be better off with a conditional block:One small issue I have with doing a straight cast in this case is code self-consistency and implicit assumptions. Maybe we can try to make things a little clearer 🤔 . Based on the call tree of
getMappedErrorMessage()
,requestEmail
is only supplied ifformCollaboratorAction
isFormCollaboratorAction.ADD
. The422
error code is not inspected in a context whereformCollaboratorAction
has been checked, so if we just castrequestEmail as string
to show we know it's true, we've implicitly stated onlyFormCollaboratorAction.ADD
returns 422. It may be true, but it's a bit dirty and not obvious from the code itself (the function signature showsrequestEmail
can beundefined
).Long story short: I'd recommend going the defensive programming route here. Either do a check to verify
requestEmail
is notundefined
like above, and have an error message for unexpected cases. Or check onformCollaboratorAction
first, and then cast to string, and you likely still need an error message for unexpected cases.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 detailed explanation. I initially assumed that it was okay to add an empty string if in the case
requestEmail
is empty because the 422 error thrown only occurs forFormCollaboratorAction.Add
. I do realise now that it is not clear in the code that that is the case and it is better just to do a simple non-null check and throw a different error ifrequestEmail
is null.