Fixing #10155 - some options errors were being swallowed and in general it was never considered to be an error state due to the 'handled' flag being consistently sent, changed the logic a bit here.

This commit is contained in:
mike12345567 2023-04-05 17:43:35 +01:00
parent b1325e4742
commit 373952a59b
3 changed files with 18 additions and 16 deletions

View File

@ -42,7 +42,7 @@
</script> </script>
{#if type === "options" && meta.constraints.inclusion.length !== 0} {#if type === "options" && meta.constraints.inclusion.length !== 0}
<Select {label} bind:value options={meta.constraints.inclusion} sort /> <Select {label} bind:value options={meta.constraints.inclusion} sort {error} />
{:else if type === "datetime"} {:else if type === "datetime"}
<DatePicker <DatePicker
{error} {error}

View File

@ -27,21 +27,22 @@
notifications.success("Row saved successfully") notifications.success("Row saved successfully")
dispatch("updaterows") dispatch("updaterows")
} catch (error) { } catch (error) {
if (error.handled) { const response = error.json
const response = error.json if (error.handled && response?.errors) {
if (response?.errors) { console.error("FIRST")
errors = response.errors errors = response.errors
} else if (response?.validationErrors) { } else if (error.handled && response?.validationErrors) {
const mappedErrors = {} console.error(response.validationErrors)
for (let field in response.validationErrors) { const mappedErrors = {}
mappedErrors[ for (let field in response.validationErrors) {
field mappedErrors[
] = `${field} ${response.validationErrors[field][0]}` field
} ] = `${field} ${response.validationErrors[field][0]}`
errors = mappedErrors
} }
errors = mappedErrors
console.log(errors)
} else { } else {
notifications.error("Failed to save row") notifications.error(`Failed to save row - ${error.message}`)
} }
// Prevent modal closing if there were errors // Prevent modal closing if there were errors
return false return false

View File

@ -7,6 +7,7 @@ CREATE TABLE Persons (
LastName varchar(255), LastName varchar(255),
FirstName varchar(255), FirstName varchar(255),
Address varchar(255), Address varchar(255),
Age INT NOT NULL,
City varchar(255) DEFAULT 'Belfast', City varchar(255) DEFAULT 'Belfast',
Type person_job Type person_job
); );
@ -42,8 +43,8 @@ CREATE TABLE test.table1 (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
Name varchar(255) Name varchar(255)
); );
INSERT INTO Persons (FirstName, LastName, Address, City, Type) VALUES ('Mike', 'Hughes', '123 Fake Street', 'Belfast', 'qa'); INSERT INTO Persons (FirstName, LastName, Address, City, Type, Age) VALUES ('Mike', 'Hughes', '123 Fake Street', 'Belfast', 'qa', 20);
INSERT INTO Persons (FirstName, LastName, Address, City, Type) VALUES ('John', 'Smith', '64 Updown Road', 'Dublin', 'programmer'); INSERT INTO Persons (FirstName, LastName, Address, City, Type, Age) VALUES ('John', 'Smith', '64 Updown Road', 'Dublin', 'programmer', 30);
INSERT INTO Tasks (ExecutorID, QaID, TaskName, Completed) VALUES (1, 2, 'assembling', TRUE); INSERT INTO Tasks (ExecutorID, QaID, TaskName, Completed) VALUES (1, 2, 'assembling', TRUE);
INSERT INTO Tasks (ExecutorID, QaID, TaskName, Completed) VALUES (2, 1, 'processing', FALSE); INSERT INTO Tasks (ExecutorID, QaID, TaskName, Completed) VALUES (2, 1, 'processing', FALSE);
INSERT INTO Products (ProductName) VALUES ('Computers'); INSERT INTO Products (ProductName) VALUES ('Computers');