FormError

This commit is contained in:
MathMan05 2024-08-26 12:12:52 -05:00
parent 39f008758b
commit a90e584790
4 changed files with 38 additions and 14 deletions

View file

@ -7,7 +7,7 @@ import { getapiurls, getBulkInfo, setTheme } from "./login.js";
import { SnowFlake } from "./snowflake.js"; import { SnowFlake } from "./snowflake.js";
import { Message } from "./message.js"; import { Message } from "./message.js";
import { Member } from "./member.js"; import { Member } from "./member.js";
import { Settings } from "./settings.js"; import { FormError, Settings } from "./settings.js";
import { MarkDown } from "./markdown.js"; import { MarkDown } from "./markdown.js";
const wsCodesRetry = new Set([4000, 4003, 4005, 4007, 4008, 4009]); const wsCodesRetry = new Set([4000, 4003, 4005, 4007, 4008, 4009]);
class Localuser { class Localuser {
@ -1045,7 +1045,7 @@ class Localuser {
return in1; return in1;
} }
else { else {
throw [copy, "Passwords don't match"]; throw new FormError(copy, "Passwords don't match");
} }
}); });
}); });

View file

@ -647,6 +647,16 @@ class Options {
} }
} }
} }
class FormError extends Error {
elem;
message;
constructor(elem, message) {
super(message);
this.message = message;
this.elem = elem;
}
}
export { FormError };
class Form { class Form {
name; name;
options; options;
@ -763,11 +773,13 @@ class Form {
build[key] = thing(); build[key] = thing();
} }
catch (e) { catch (e) {
const elm = this.options.html.get(e[0]); if (e instanceof FormError) {
if (elm) { const elm = this.options.html.get(e.elem);
const html = elm.deref(); if (elm) {
if (html) { const html = elm.deref();
this.makeError(html, e[1]); if (html) {
this.makeError(html, e.message);
}
} }
} }
return; return;

View file

@ -9,7 +9,7 @@ import { SnowFlake } from "./snowflake.js";
import { Message } from "./message.js"; import { Message } from "./message.js";
import { channeljson, memberjson, presencejson, readyjson } from "./jsontypes.js"; import { channeljson, memberjson, presencejson, readyjson } from "./jsontypes.js";
import { Member } from "./member.js"; import { Member } from "./member.js";
import { Settings } from "./settings.js"; import { FormError, Settings } from "./settings.js";
import { MarkDown } from "./markdown.js"; import { MarkDown } from "./markdown.js";
const wsCodesRetry=new Set([4000,4003,4005,4007,4008,4009]); const wsCodesRetry=new Set([4000,4003,4005,4007,4008,4009]);
@ -1052,7 +1052,7 @@ class Localuser{
if(in1===in2){ if(in1===in2){
return in1; return in1;
}else{ }else{
throw [copy,"Passwords don't match"] throw new FormError(copy,"Passwords don't match");
} }
}) })
}); });

View file

@ -649,6 +649,16 @@ class Options implements OptionsElement<void>{
} }
} }
} }
class FormError extends Error{
elem:OptionsElement<any>;
message:string;
constructor(elem:OptionsElement<any>,message:string){
super(message);
this.message=message;
this.elem=elem;
}
}
export {FormError};
class Form implements OptionsElement<object>{ class Form implements OptionsElement<object>{
name:string; name:string;
readonly options:Options; readonly options:Options;
@ -766,11 +776,13 @@ class Form implements OptionsElement<object>{
try{ try{
build[key]=thing(); build[key]=thing();
}catch(e:any){ }catch(e:any){
const elm=this.options.html.get(e[0]); if(e instanceof FormError){
if(elm){ const elm=this.options.html.get(e.elem);
const html=elm.deref(); if(elm){
if(html){ const html=elm.deref();
this.makeError(html,e[1]); if(html){
this.makeError(html,e.message);
}
} }
} }
return; return;