mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
error handling levels
This commit is contained in:
@@ -25,6 +25,8 @@ import VIEWS from '../../../../../views/v1/routes';
|
||||
import validateDescription from './validateDescription';
|
||||
import validateDuration from './validateDuration';
|
||||
|
||||
import createError from '../../../../../components/error';
|
||||
|
||||
const SITE_KEY_FORM_CLASS = 'sitekey-form';
|
||||
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));
|
||||
if (res.ok) {
|
||||
alert('success');
|
||||
const data = await res.json();
|
||||
window.location.assign(VIEWS.listSitekey(data.key));
|
||||
} else {
|
||||
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 {mockAlert} from '../../../../../setUpTests';
|
||||
|
||||
import setup from '../../../../../components/error/setUpTests';
|
||||
|
||||
mockAlert();
|
||||
|
||||
document.body.innerHTML = getAddForm();
|
||||
@@ -26,6 +28,7 @@ document.body.innerHTML = getAddForm();
|
||||
const emptyErr = "can't be empty";
|
||||
|
||||
it('validateDescription workds', () => {
|
||||
document.querySelector('body').appendChild(setup());
|
||||
try {
|
||||
const event = new Event('submit');
|
||||
validateDescription(event);
|
||||
|
||||
Reference in New Issue
Block a user