Skip to content

Commit

Permalink
Added descriptor to error responses
Browse files Browse the repository at this point in the history
  • Loading branch information
nuxy committed Apr 21, 2024
1 parent adc5b33 commit 8284f64
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/webform-toolkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function WebformToolkit(container, settings, callback) {
break;

default:
throw new Error('Invalid or missing field type');
throw new Error(`Invalid field type: ${config.type}`);
}

config?.id && elm.setAttribute('id', config.id);
Expand Down Expand Up @@ -566,7 +566,11 @@ function WebformToolkit(container, settings, callback) {
function setButtonState(form) {
const button = form.querySelector('input[type="submit"]');

button.disabled = checkErrorsExist(form);
if (button) {
button.disabled = checkErrorsExist(form);
} else {
throw new Error('Failed to change submit state (missing field)')
}
}

/**
Expand Down Expand Up @@ -607,7 +611,7 @@ function WebformToolkit(container, settings, callback) {
if (form && elm && typeof callback === 'function') {
callback(form, elm);
} else {
throw new Error('Failed to create (malformed config)');
throw new Error(`Failed to create field: ${elm.name} (malformed config)`);
}
};

Expand Down

0 comments on commit 8284f64

Please sign in to comment.