mirror of
https://github.com/theoludwig/theoludwig.git
synced 2024-12-08 00:44:30 +01:00
fix: try/catch inside middleware when checking locale
This commit is contained in:
parent
137cceffa1
commit
35211fa279
@ -17,12 +17,16 @@ export const middleware = (request: NextRequest): NextResponse => {
|
|||||||
|
|
||||||
let locale = request.cookies.get('locale')?.value
|
let locale = request.cookies.get('locale')?.value
|
||||||
if (locale == null || !LOCALES.includes(locale as Locale)) {
|
if (locale == null || !LOCALES.includes(locale as Locale)) {
|
||||||
|
try {
|
||||||
const headers = {
|
const headers = {
|
||||||
'accept-language':
|
'accept-language':
|
||||||
request.headers.get('accept-language') ?? DEFAULT_LOCALE
|
request.headers.get('accept-language') ?? DEFAULT_LOCALE
|
||||||
}
|
}
|
||||||
const languages = new Negotiator({ headers }).languages()
|
const languages = new Negotiator({ headers }).languages()
|
||||||
locale = match(languages, LOCALES.slice(), DEFAULT_LOCALE)
|
locale = match(languages, LOCALES.slice(), DEFAULT_LOCALE)
|
||||||
|
} catch {
|
||||||
|
locale = DEFAULT_LOCALE
|
||||||
|
}
|
||||||
response.cookies.set('locale', locale, {
|
response.cookies.set('locale', locale, {
|
||||||
path: '/',
|
path: '/',
|
||||||
maxAge: COOKIE_MAX_AGE
|
maxAge: COOKIE_MAX_AGE
|
||||||
|
Loading…
Reference in New Issue
Block a user