Skip to content

Commit d96468d

Browse files
authored
fix: further improve error message format/clarity | GBI-2642 (#716)
* fix: improve error message format | GBI-2642 * fix: golang-cli * fix: add getCustomValidationMessage function * fix: move error handling to FE
1 parent f7ff155 commit d96468d

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

internal/adapters/entrypoints/rest/assets/static/configUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ async function postConfig(sectionId, endpoint, config, csrfToken) {
108108
}
109109
return true;
110110
} catch (error) {
111-
throw new Error(`Error during ${sectionId} configuration save: ${error.message}`);
111+
throw new Error(`${sectionId}: ${error.message}`);
112112
}
113113
}
114114

internal/adapters/entrypoints/rest/assets/static/management.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ const createFeeInput = (inputContainer, label, section, key, value) => {
136136

137137
const createFeePercentageInput = (inputContainer, section, key, value) => {
138138
const input = document.createElement('input');
139-
input.type = 'text';
139+
input.type = 'number';
140+
input.min = '0';
141+
input.max = '100';
142+
input.step = 'any';
140143
input.style.width = '40%';
141144
input.classList.add('form-control');
142145
input.dataset.key = key;
@@ -389,7 +392,7 @@ function checkFeeWarnings() {
389392
const existingToast = document.getElementById('warningToast');
390393
if (shouldWarn) {
391394
if (!existingToast) {
392-
showWarningToast('You have configured a zero-fee setting. This means you wont earn fees from bridging transactions.');
395+
showWarningToast('You have configured a zero-fee setting. This means you won\'t earn fees from bridging transactions.');
393396
} else {
394397
bootstrap.Toast.getOrCreateInstance(existingToast).show();
395398
}
@@ -464,13 +467,21 @@ function getRegularConfig(sectionId) {
464467
try {
465468
value = etherToWei(input.value).toString();
466469
} catch (error) {
467-
showErrorToast(`Invalid input "${input.value}" for field "${key}". Please enter a valid number.`);
470+
showErrorToast(`"${sectionId}": Invalid input "${input.value}" for field "${key}". Please enter a valid number.`);
468471
throw error;
469472
}
470473
} else if (isfeePercentageKey(key)) {
471474
value = parseFloat(input.value.trim());
472475
if (isNaN(value)) {
473-
showErrorToast(`Invalid input "${input.value}" for feePercentage. Please enter a valid number.`);
476+
showErrorToast(`"${sectionId}": Invalid percentage entered "${input.value}". Please provide a valid value between 0% and 100%.`);
477+
throw new Error('Invalid feePercentage');
478+
}
479+
if (value < 0) {
480+
showErrorToast(`"${sectionId}": Fee percentage cannot be negative. Please enter a value between 0% and 100%.`);
481+
throw new Error('Invalid feePercentage');
482+
}
483+
if (value > 100) {
484+
showErrorToast(`"${sectionId}": Fee percentage cannot exceed 100%. Please enter a value between 0% and 100%.`);
474485
throw new Error('Invalid feePercentage');
475486
}
476487
} else {

0 commit comments

Comments
 (0)