Skip to content

Commit

Permalink
fix and debug for translate endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbedouret committed Sep 6, 2024
1 parent 38e889a commit c0c01d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ const nextConfig = {
port: '',
pathname: '/**',
},
{
protocol: 'https',
hostname: '**.microsofttranslator.com',
port: '',
pathname: '/**',
},
],
},
reactStrictMode: false,
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/azure-services/translate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ export async function POST(req: Request) {
from: from,
},
});

if (isUnexpected(translateResponse)) {
console.error(translateResponse.body.error);
} else {
const translations = translateResponse.body;
console.log(translations);
if (translations instanceof Array) {
return NextResponse.json({
translation: translations[0].translations[0].text,
});
}
}
return NextResponse.json(
{ error: `Error detecting language for: ${description}` },
{ error: `Error translating from: ${from} the word: ${description}.` },
{ status: 500 },
);
} catch (error) {
Expand Down

0 comments on commit c0c01d8

Please sign in to comment.