🐛 Fix matcher throwing error (#1634)

This commit is contained in:
Luke Vella 2025-03-14 13:35:51 +00:00 committed by GitHub
parent 5bf579a62f
commit f075c98f6e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 6 deletions

View file

@ -5,13 +5,19 @@ import type { NextRequest } from "next/server";
const locales = Object.keys(languages);
export async function getPreferredLocale(req: NextRequest) {
export function getPreferredLocale(req: NextRequest) {
const preferredLanguages = new Negotiator({
headers: {
"accept-language": req.headers.get("accept-language") ?? "",
},
}).languages();
})
.languages()
.filter((lang) => lang !== "*");
const locale = match(preferredLanguages, locales, defaultLocale);
return locale;
try {
return match(preferredLanguages, locales, defaultLocale);
} catch (e) {
console.warn("Failed to match locale", e);
return defaultLocale;
}
}