Skip to content

Commit

Permalink
Merge pull request #537 from DTS-STN/handle-urlcat-error
Browse files Browse the repository at this point in the history
fix(frontend): handle urlcat error
  • Loading branch information
sebastien-comeau authored Dec 20, 2023
2 parents c816812 + c7905a4 commit 99308b6
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 99308b6

Please sign in to comment.