fix: use new for throw error
Co-Authored-By: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
This commit is contained in:
parent
78f061b9db
commit
f3164c9cf2
@ -27,7 +27,7 @@ html
|
|||||||
.then(registrations => {
|
.then(registrations => {
|
||||||
return Promise.all(registrations.map(registration => registration.unregister()));
|
return Promise.all(registrations.map(registration => registration.unregister()));
|
||||||
})
|
})
|
||||||
.catch(e => { throw Error(e) });
|
.catch(e => { throw new Error(e) });
|
||||||
}
|
}
|
||||||
|
|
||||||
message(successText);
|
message(successText);
|
||||||
|
@ -132,27 +132,27 @@ function isObject(value: unknown): value is Record<string, unknown> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function validate(profile: unknown): void {
|
function validate(profile: unknown): void {
|
||||||
if (!isObject(profile)) throw Error('not an object');
|
if (!isObject(profile)) throw new Error('not an object');
|
||||||
|
|
||||||
// Check if unnecessary properties exist
|
// Check if unnecessary properties exist
|
||||||
if (Object.keys(profile).some(key => !profileProps.includes(key))) throw Error('Unnecessary properties exist');
|
if (Object.keys(profile).some(key => !profileProps.includes(key))) throw new Error('Unnecessary properties exist');
|
||||||
|
|
||||||
if (!profile.name) throw Error('Missing required prop: name');
|
if (!profile.name) throw new Error('Missing required prop: name');
|
||||||
if (!profile.misskeyVersion) throw Error('Missing required prop: misskeyVersion');
|
if (!profile.misskeyVersion) throw new Error('Missing required prop: misskeyVersion');
|
||||||
|
|
||||||
// Check if createdAt and updatedAt is Date
|
// Check if createdAt and updatedAt is Date
|
||||||
// https://zenn.dev/lollipop_onl/articles/eoz-judge-js-invalid-date
|
// https://zenn.dev/lollipop_onl/articles/eoz-judge-js-invalid-date
|
||||||
if (!profile.createdAt || Number.isNaN(new Date(profile.createdAt).getTime())) throw Error('createdAt is falsy or not Date');
|
if (!profile.createdAt || Number.isNaN(new Date(profile.createdAt).getTime())) throw new Error('createdAt is falsy or not Date');
|
||||||
if (profile.updatedAt) {
|
if (profile.updatedAt) {
|
||||||
if (Number.isNaN(new Date(profile.updatedAt).getTime())) {
|
if (Number.isNaN(new Date(profile.updatedAt).getTime())) {
|
||||||
throw Error('updatedAt is not Date');
|
throw new Error('updatedAt is not Date');
|
||||||
}
|
}
|
||||||
} else if (profile.updatedAt !== null) {
|
} else if (profile.updatedAt !== null) {
|
||||||
throw Error('updatedAt is not null');
|
throw new Error('updatedAt is not null');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!profile.settings) throw Error('Missing required prop: settings');
|
if (!profile.settings) throw new Error('Missing required prop: settings');
|
||||||
if (!isObject(profile.settings)) throw Error('Invalid prop: settings');
|
if (!isObject(profile.settings)) throw new Error('Invalid prop: settings');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSettings(): Profile['settings'] {
|
function getSettings(): Profile['settings'] {
|
||||||
|
Loading…
Reference in New Issue
Block a user