Skip to content

Commit

Permalink
chore: 백앤드 로그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
yunochi committed Nov 23, 2024
1 parent ddb5ea2 commit 697c568
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
13 changes: 8 additions & 5 deletions src/app/api/db/create-question/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export async function POST(req: NextRequest) {
try {
data = await validateStrict(CreateQuestionDto, await req.json());
} catch (errors) {
logger.warn(errors);
return sendErrorResponse(400, `${errors}`);
}

Expand All @@ -59,8 +60,10 @@ export async function POST(req: NextRequest) {
});

if (questionee_profile.stopAnonQuestion && !data.questioner) {
logger.debug('The user has prohibits anonymous questions.');
throw new Error('The user has prohibits anonymous questions.');
} else if (questionee_profile.stopNewQuestion) {
logger.debug('User stops NewQuestion');
throw new Error('User stops NewQuestion');
}

Expand Down Expand Up @@ -99,9 +102,7 @@ export async function POST(req: NextRequest) {
} else {
// 알림 전송
const url = `${process.env.WEB_URL}/main/questions`;
setImmediate(() => {
sendNotify(questionee_user, newQuestion.question, url);
});
sendNotify(questionee_user, newQuestion.question, url);
}

// notify send 기다라지 않고 200반환
Expand All @@ -127,8 +128,10 @@ async function sendNotify(questionee: user, question: string, url: string): Prom
text: `${questionee.handle} <네오-퀘스돈> 새로운 질문이에요!\nQ. ${question}\n ${url}`,
}),
});
if (res.ok === false) {
throw new Error(`Note create error`);
if (!res.ok) {
throw new Error(`Note create error ${await res.text()}`);
} else {
logger.log(`Notification Sent to ${questionee.handle}`);
}
} catch (error) {
logger.error('Post-question: fail to send notify: ', error);
Expand Down
30 changes: 19 additions & 11 deletions src/app/main/questions/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,22 @@ async function mkMisskeyNote(
text: text,
visibility: visibility,
};
const res = await fetch(`https://${hostname}/api/notes/create`, {
method: 'POST',
headers: {
Authorization: `Bearer ${i}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(newAnswerNote),
});
if (!res.ok) {
NoteLogger.warn(`Note create fail! `, res.status, res.statusText);
try {
const res = await fetch(`https://${hostname}/api/notes/create`, {
method: 'POST',
headers: {
Authorization: `Bearer ${i}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(newAnswerNote),
});
if (!res.ok) {
throw new Error(`Note Create Fail! ${await res.text()}`);
} else {
NoteLogger.log(`Note Created! ${res.statusText}`);
}
} catch (err) {
NoteLogger.warn(err);
}
}

Expand Down Expand Up @@ -197,7 +203,9 @@ async function mastodonToot(
});

if (!res.ok) {
throw new Error(`HTTP Error! status:${res.status}`);
throw new Error(`HTTP Error! status:${await res.text()}`);
} else {
tootLogger.log(`Toot Created! ${res.statusText}`);
}
} catch (err) {
tootLogger.warn(`Toot Create Fail!`, err);
Expand Down

0 comments on commit 697c568

Please sign in to comment.