mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-03-29 04:38:59 +03:00
error handling levels
This commit is contained in:
parent
f10741d09f
commit
96fafb339c
5 changed files with 15 additions and 4 deletions
|
@ -25,6 +25,8 @@ import VIEWS from '../../../../../views/v1/routes';
|
||||||
import validateDescription from './validateDescription';
|
import validateDescription from './validateDescription';
|
||||||
import validateDuration from './validateDuration';
|
import validateDuration from './validateDuration';
|
||||||
|
|
||||||
|
import createError from '../../../../../components/error';
|
||||||
|
|
||||||
const SITE_KEY_FORM_CLASS = 'sitekey-form';
|
const SITE_KEY_FORM_CLASS = 'sitekey-form';
|
||||||
const FORM = <HTMLFormElement>document.querySelector(`.${SITE_KEY_FORM_CLASS}`);
|
const FORM = <HTMLFormElement>document.querySelector(`.${SITE_KEY_FORM_CLASS}`);
|
||||||
|
|
||||||
|
@ -53,12 +55,11 @@ const submit = async (e: Event) => {
|
||||||
|
|
||||||
const res = await fetch(formUrl, genJsonPayload(payload));
|
const res = await fetch(formUrl, genJsonPayload(payload));
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
alert('success');
|
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
window.location.assign(VIEWS.listSitekey(data.key));
|
window.location.assign(VIEWS.listSitekey(data.key));
|
||||||
} else {
|
} else {
|
||||||
const err = await res.json();
|
const err = await res.json();
|
||||||
alert(`error: ${err.error}`);
|
createError(err.error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@ import validateDescription from './validateDescription';
|
||||||
import {getAddForm, fillDescription} from '../setupTests';
|
import {getAddForm, fillDescription} from '../setupTests';
|
||||||
import {mockAlert} from '../../../../../setUpTests';
|
import {mockAlert} from '../../../../../setUpTests';
|
||||||
|
|
||||||
|
import setup from '../../../../../components/error/setUpTests';
|
||||||
|
|
||||||
mockAlert();
|
mockAlert();
|
||||||
|
|
||||||
document.body.innerHTML = getAddForm();
|
document.body.innerHTML = getAddForm();
|
||||||
|
@ -26,6 +28,7 @@ document.body.innerHTML = getAddForm();
|
||||||
const emptyErr = "can't be empty";
|
const emptyErr = "can't be empty";
|
||||||
|
|
||||||
it('validateDescription workds', () => {
|
it('validateDescription workds', () => {
|
||||||
|
document.querySelector('body').appendChild(setup());
|
||||||
try {
|
try {
|
||||||
const event = new Event('submit');
|
const event = new Event('submit');
|
||||||
validateDescription(event);
|
validateDescription(event);
|
||||||
|
|
|
@ -19,6 +19,8 @@ import CONST from '../const';
|
||||||
import getLevelFields from './getLevelFields';
|
import getLevelFields from './getLevelFields';
|
||||||
import {LEVELS} from './index';
|
import {LEVELS} from './index';
|
||||||
|
|
||||||
|
import createError from '../../../../../components/error';
|
||||||
|
|
||||||
/** on-change event handler to update level */
|
/** on-change event handler to update level */
|
||||||
const updateLevel = (e: Event) => {
|
const updateLevel = (e: Event) => {
|
||||||
const target = <HTMLInputElement>e.target;
|
const target = <HTMLInputElement>e.target;
|
||||||
|
@ -41,7 +43,7 @@ const updateLevel = (e: Event) => {
|
||||||
const updatedLevel = getLevelFields(level);
|
const updatedLevel = getLevelFields(level);
|
||||||
LEVELS.update(updatedLevel, level);
|
LEVELS.update(updatedLevel, level);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert(e);
|
createError(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,15 @@
|
||||||
import isBlankString from './isBlankString';
|
import isBlankString from './isBlankString';
|
||||||
import {mockAlert} from '../setUpTests';
|
import {mockAlert} from '../setUpTests';
|
||||||
|
|
||||||
|
|
||||||
|
import setup from '../components/error/setUpTests';
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
mockAlert();
|
mockAlert();
|
||||||
|
|
||||||
it('getFromUrl workds', () => {
|
it('getFromUrl workds', () => {
|
||||||
|
document.querySelector('body').appendChild(setup());
|
||||||
expect(isBlankString('test', 'username')).toBe(false);
|
expect(isBlankString('test', 'username')).toBe(false);
|
||||||
try {
|
try {
|
||||||
isBlankString(' ', 'username');
|
isBlankString(' ', 'username');
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
import createError from '../components/error/';
|
||||||
|
|
||||||
const isBlankString = (value: string|number, field: string, event?: Event) => {
|
const isBlankString = (value: string|number, field: string, event?: Event) => {
|
||||||
value = value.toString();
|
value = value.toString();
|
||||||
|
@ -22,7 +23,7 @@ const isBlankString = (value: string|number, field: string, event?: Event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
const msg = `${field} can't be empty`;
|
const msg = `${field} can't be empty`;
|
||||||
alert(msg);
|
createError(msg);
|
||||||
throw new Error(msg);
|
throw new Error(msg);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue