Skip to content
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

Added Validation block for validation errors #11152

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/Utils/Notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@ const formatKey = (key: string) => {

const notifyError = (error: any) => {
let errorMsg = "";

if (
error?.type === "validation_error" &&
error?.msg &&
typeof error.msg === "object"
) {
Object.values(error.msg).forEach((messages) => {
if (Array.isArray(messages)) {
errorMsg += messages.join(", ");
} else {
errorMsg += messages;
}
});

if (errorMsg.length > 0) {
toast.error(errorMsg);
} else {
toast.error("Something went wrong , please upload different image");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to add translation.

Please follow the merge check list to avoid these mistakes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

}
return;
}
Comment on lines +25 to +44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

❓ Verification inconclusive

Test coverage for the new validation block.

The new validation error handling block handles a specific error format. Make sure to add tests for this scenario to ensure it works as expected for various validation error structures.

Please verify that there are unit tests covering this new validation error handling logic, especially with:

  1. Various message structures (arrays, strings)
  2. Empty msg object
  3. Different validation error types

🏁 Script executed:

#!/bin/bash
# Search for test files that might test the notifyError function
fd -t f "test|spec" --exec grep -l "notifyError" {} \;

Length of output: 57


Attention: Missing Unit Tests for New Validation Logic

It appears that our automated search didn’t locate any test files referencing the validation error handling (e.g. via “notifyError” or “validation_error”) in our test or spec directories. Please manually verify if tests exist under alternate naming conventions. If not, add unit tests covering the following cases:

  • Array messages: Verify that an error message constructed from an array (joined via commas) is correctly handled.
  • String messages: Confirm that single-message (non-array) errors are processed properly.
  • Empty msg object: Ensure that an empty or missing message object falls back to the default error.
  • Different error types: Test that only errors with error?.type === "validation_error" trigger this logic, while others fall back accordingly.


if (typeof error === "string" || !error) {
errorMsg =
!error || error.length > 100 ? "Something went wrong...!" : error;
Expand Down