-
Notifications
You must be signed in to change notification settings - Fork 153
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
Display MySQL user defined error in API Key UI #4590
Merged
kentakozuka
merged 4 commits into
pipe-cd:master
from
kentakozuka:display-user-defined-error-mysql
Sep 7, 2023
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ import { | |
DISABLE_API_KEY_SUCCESS, | ||
GENERATE_API_KEY_SUCCESS, | ||
} from "~/constants/toast-text"; | ||
import { useAppDispatch, useAppSelector } from "~/hooks/redux"; | ||
import { unwrapResult, useAppDispatch, useAppSelector } from "~/hooks/redux"; | ||
import { | ||
APIKey, | ||
disableAPIKey, | ||
|
@@ -96,10 +96,16 @@ export const APIKeyPage: FC = memo(function APIKeyPage() { | |
|
||
const handleSubmit = useCallback( | ||
(values: { name: string; role: APIKey.Role }) => { | ||
dispatch(generateAPIKey(values)).then(() => { | ||
dispatch(fetchAPIKeys({ enabled: true })); | ||
dispatch(addToast({ message: GENERATE_API_KEY_SUCCESS })); | ||
}); | ||
dispatch(generateAPIKey(values)) | ||
.then(unwrapResult) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixes an existing bug that success toast is displayed even if a request fails. |
||
.then(() => { | ||
console.log("handleSubmit.then"); | ||
dispatch(fetchAPIKeys({ enabled: true })); | ||
dispatch( | ||
addToast({ message: GENERATE_API_KEY_SUCCESS, severity: "success" }) | ||
); | ||
}) | ||
.catch(() => undefined); | ||
}, | ||
[dispatch] | ||
); | ||
|
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
Oops, something went wrong.
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.
Why do we have to change from switch case to multiple if 🤔
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.
If we generate an error with a message from MySQL, handling errors with a switch cannot work properly. That's why I had to change it to multi-if blocks.
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.
Which means the switch block can not check the type of datastore.ErrUserDefined error 🤔 It's a bit weird to me. Btw, how about adding test for this function. Looks like this function is testable without mocking anything.
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.
When an error message from MySQL is added to datastore.ErrUserDefined, checking with the switch block does not work because the new error is no longer the same as datastore.ErrUserDefined.
I agree with you to add tests for it 👍
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.
Added tests.