Skip to content

Commit

Permalink
fix(frontend): handle urlcat error
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien-comeau committed Dec 20, 2023
1 parent c816812 commit c7905a4
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions frontend/src/next-seo.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { OpenGraphMedia } from 'next-seo/lib/types'
import { Router } from 'next/router'
import urlcat from 'urlcat'

import { getLogger } from './logging/log-util'

const logger = getLogger('next-seo-config')

export type NextSEORouter = Pick<Router, 'asPath' | 'locale'>

export interface LanguageAlternate {
Expand All @@ -12,19 +16,27 @@ export interface LanguageAlternate {

export const getLanguageAlternates = (
appBaseUri: string,
router: NextSEORouter
router: NextSEORouter,
): ReadonlyArray<LanguageAlternate> | undefined => {
if (!appBaseUri) return
return [
{
hrefLang: 'en',
href: urlcat(appBaseUri, `/en${router.asPath}`),
},
{
hrefLang: 'fr',
href: urlcat(appBaseUri, `/fr${router.asPath}`),
},
]
try {
return [
{
hrefLang: 'en',
href: urlcat(appBaseUri, `/en${router.asPath}`),
},
{
hrefLang: 'fr',
href: urlcat(appBaseUri, `/fr${router.asPath}`),
},
]
} catch (error) {
const message =
error instanceof Error
? `Unable to perform operation getLanguageAlternates due to: ${error.message}`
: `Unknown error occurred`
logger.error(error, message)
}
}

export const getOpenGraphImages = (appBaseUri: string): ReadonlyArray<OpenGraphMedia> | undefined => {
Expand Down

0 comments on commit c7905a4

Please sign in to comment.