Skip to content

Commit

Permalink
fix: if s3 error
Browse files Browse the repository at this point in the history
  • Loading branch information
ymzuiku committed Oct 7, 2023
1 parent ad985b5 commit b07f160
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/lib/server/sentence/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,29 @@ export async function analyze(input: AnalyzeInput): Promise<AnalyzeClient> {
if (!old.hashQuestion) {
throw i18nKey('历史hash未找到');
}
const answer = await s3
.getObject({ Bucket: AWS_S3_SENTENCES, Key: old.hashQuestion! })
.promise();

if (!answer.Body) {
throw i18nKey('未找到历史分析信息');
try {
const answer = await s3
.getObject({ Bucket: AWS_S3_SENTENCES, Key: old.hashQuestion! })
.promise();
if (!answer.Body) {
throw i18nKey('未找到历史分析信息');
}
return {
...old,
answer: JSON.parse(String(answer.Body)),
} as unknown as AnalyzeClient;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
if (err?.message?.indexOf('specified key does') > 0) {
await prisma.analyze.delete({
where: {
id: old.id,
},
});
throw i18nKey('未找到历史分析信息');
}
throw err;
}
return {
...old,
answer: JSON.parse(String(answer.Body)),
} as unknown as AnalyzeClient;
}
}

Expand Down

0 comments on commit b07f160

Please sign in to comment.