From f3164c9cf2d51ae2b7ca5e0d5880e31b5d341959 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 1 Aug 2022 17:44:53 +0900 Subject: [PATCH] fix: use new for throw error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Acid Chicken (硫酸鶏) --- .../backend/src/server/web/views/flush.pug | 2 +- .../src/pages/settings/preferences-backups.vue | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/backend/src/server/web/views/flush.pug b/packages/backend/src/server/web/views/flush.pug index ec585a34db..a73a45212f 100644 --- a/packages/backend/src/server/web/views/flush.pug +++ b/packages/backend/src/server/web/views/flush.pug @@ -27,7 +27,7 @@ html .then(registrations => { return Promise.all(registrations.map(registration => registration.unregister())); }) - .catch(e => { throw Error(e) }); + .catch(e => { throw new Error(e) }); } message(successText); diff --git a/packages/client/src/pages/settings/preferences-backups.vue b/packages/client/src/pages/settings/preferences-backups.vue index 3653e2dc1d..991bb7902d 100644 --- a/packages/client/src/pages/settings/preferences-backups.vue +++ b/packages/client/src/pages/settings/preferences-backups.vue @@ -132,27 +132,27 @@ function isObject(value: unknown): value is Record { } 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 - 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.misskeyVersion) throw Error('Missing required prop: misskeyVersion'); + if (!profile.name) throw new Error('Missing required prop: name'); + if (!profile.misskeyVersion) throw new Error('Missing required prop: misskeyVersion'); // Check if createdAt and updatedAt is 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 (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) { - throw Error('updatedAt is not null'); + throw new Error('updatedAt is not null'); } - if (!profile.settings) throw Error('Missing required prop: settings'); - if (!isObject(profile.settings)) throw Error('Invalid prop: settings'); + if (!profile.settings) throw new Error('Missing required prop: settings'); + if (!isObject(profile.settings)) throw new Error('Invalid prop: settings'); } function getSettings(): Profile['settings'] {