Better error handling
This commit is contained in:
parent
b390363b25
commit
e3b3f8fac1
25 changed files with 52 additions and 52 deletions
|
|
@ -11,7 +11,7 @@ export async function extractPollFromQuestion(source: string | IQuestion): Promi
|
|||
const expiresAt = question.endTime ? new Date(question.endTime) : null;
|
||||
|
||||
if (multiple && !question.anyOf) {
|
||||
throw 'invalid question';
|
||||
throw new Error('invalid question');
|
||||
}
|
||||
|
||||
const choices = question[multiple ? 'anyOf' : 'oneOf']!
|
||||
|
|
@ -37,14 +37,14 @@ export async function updateQuestion(value: any) {
|
|||
const uri = typeof value == 'string' ? value : value.id;
|
||||
|
||||
// URIがこのサーバーを指しているならスキップ
|
||||
if (uri.startsWith(config.url + '/')) throw 'uri points local';
|
||||
if (uri.startsWith(config.url + '/')) throw new Error('uri points local');
|
||||
|
||||
//#region このサーバーに既に登録されているか
|
||||
const note = await Notes.findOne({ uri });
|
||||
if (note == null) throw 'Question is not registed';
|
||||
if (note == null) throw new Error('Question is not registed');
|
||||
|
||||
const poll = await Polls.findOne({ noteId: note.id });
|
||||
if (poll == null) throw 'Question is not registed';
|
||||
if (poll == null) throw new Error('Question is not registed');
|
||||
//#endregion
|
||||
|
||||
// resolve new Question object
|
||||
|
|
@ -52,7 +52,7 @@ export async function updateQuestion(value: any) {
|
|||
const question = await resolver.resolve(value) as IQuestion;
|
||||
apLogger.debug(`fetched question: ${JSON.stringify(question, null, 2)}`);
|
||||
|
||||
if (question.type !== 'Question') throw 'object is not a Question';
|
||||
if (question.type !== 'Question') throw new Error('object is not a Question');
|
||||
|
||||
const apChoices = question.oneOf || question.anyOf;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue