error handling levels

This commit is contained in:
realaravinth
2021-06-29 23:20:54 +05:30
parent f10741d09f
commit 96fafb339c
5 changed files with 15 additions and 4 deletions

View File

@@ -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);
}
};