fix: update meta handling in AnnuncioDettaglio and improve error messages in getAnnunciByCod and getAnnunciMetaByCod

This commit is contained in:
Marco Pedone 2025-08-27 10:56:13 +02:00
parent f20869d7fe
commit eba4e31d38
2 changed files with 12 additions and 14 deletions

View file

@ -68,7 +68,7 @@ type AnnuncioProps = {
title: string;
description: string;
ogUrl: string;
};
} | null;
};
const AnnuncioDettaglio: NextPage<AnnuncioProps> = ({
cod,
@ -78,13 +78,13 @@ const AnnuncioDettaglio: NextPage<AnnuncioProps> = ({
return (
<main>
<Head>
<title>{`${cod} | ${meta.title}`}</title>
<meta property="description" content={meta.description} />
<meta property="og:url" content={meta.ogUrl} />
<title>{`${cod} | ${meta?.title}`}</title>
<meta property="description" content={meta?.description} />
<meta property="og:url" content={meta?.ogUrl} />
<meta property="og:type" content="website" />
<meta property="og:title" content={`${cod} | ${meta.title}`} />
<meta property="og:description" content={meta.description} />
<meta property="og:image" content={meta.ogImage} />
<meta property="og:title" content={`${cod} | ${meta?.title}`} />
<meta property="og:description" content={meta?.description} />
<meta property="og:image" content={meta?.ogImage} />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta

View file

@ -74,8 +74,8 @@ export const getAnnunciByCod = async ({
.where("annunci.web", "=", true)
.where("codice", "=", cod)
.executeTakeFirst();
if (!annuncio) {
console.error("Annuncio non trovato per codice:", cod);
return null;
}
@ -83,7 +83,8 @@ export const getAnnunciByCod = async ({
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Errore query getAnnuncio: " + (e as Error).message,
message: "Errore query getAnnunciByCod: " + (e as Error).message,
cause: (e as Error).cause,
});
}
};
@ -96,10 +97,7 @@ export const getAnnunciMetaByCod = async ({ cod }: { cod: string }) => {
.where("codice", "=", cod)
.executeTakeFirst();
if (!annuncio) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Annuncio non trovato",
});
return null;
}
return {
@ -111,7 +109,7 @@ export const getAnnunciMetaByCod = async ({ cod }: { cod: string }) => {
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Errore query getAnnuncio: " + (e as Error).message,
message: "Errore query getAnnunciMetaByCod: " + (e as Error).message,
});
}
};