fix: update meta handling in AnnuncioDettaglio and improve error messages in getAnnunciByCod and getAnnunciMetaByCod
This commit is contained in:
parent
f20869d7fe
commit
eba4e31d38
2 changed files with 12 additions and 14 deletions
|
|
@ -68,7 +68,7 @@ type AnnuncioProps = {
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
ogUrl: string;
|
ogUrl: string;
|
||||||
};
|
} | null;
|
||||||
};
|
};
|
||||||
const AnnuncioDettaglio: NextPage<AnnuncioProps> = ({
|
const AnnuncioDettaglio: NextPage<AnnuncioProps> = ({
|
||||||
cod,
|
cod,
|
||||||
|
|
@ -78,13 +78,13 @@ const AnnuncioDettaglio: NextPage<AnnuncioProps> = ({
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
<Head>
|
<Head>
|
||||||
<title>{`${cod} | ${meta.title}`}</title>
|
<title>{`${cod} | ${meta?.title}`}</title>
|
||||||
<meta property="description" content={meta.description} />
|
<meta property="description" content={meta?.description} />
|
||||||
<meta property="og:url" content={meta.ogUrl} />
|
<meta property="og:url" content={meta?.ogUrl} />
|
||||||
<meta property="og:type" content="website" />
|
<meta property="og:type" content="website" />
|
||||||
<meta property="og:title" content={`${cod} | ${meta.title}`} />
|
<meta property="og:title" content={`${cod} | ${meta?.title}`} />
|
||||||
<meta property="og:description" content={meta.description} />
|
<meta property="og:description" content={meta?.description} />
|
||||||
<meta property="og:image" content={meta.ogImage} />
|
<meta property="og:image" content={meta?.ogImage} />
|
||||||
<meta property="og:image:width" content="1200" />
|
<meta property="og:image:width" content="1200" />
|
||||||
<meta property="og:image:height" content="630" />
|
<meta property="og:image:height" content="630" />
|
||||||
<meta
|
<meta
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,8 @@ export const getAnnunciByCod = async ({
|
||||||
.where("annunci.web", "=", true)
|
.where("annunci.web", "=", true)
|
||||||
.where("codice", "=", cod)
|
.where("codice", "=", cod)
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|
||||||
if (!annuncio) {
|
if (!annuncio) {
|
||||||
console.error("Annuncio non trovato per codice:", cod);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,7 +83,8 @@ export const getAnnunciByCod = async ({
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "INTERNAL_SERVER_ERROR",
|
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)
|
.where("codice", "=", cod)
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
if (!annuncio) {
|
if (!annuncio) {
|
||||||
throw new TRPCError({
|
return null;
|
||||||
code: "NOT_FOUND",
|
|
||||||
message: "Annuncio non trovato",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -111,7 +109,7 @@ export const getAnnunciMetaByCod = async ({ cod }: { cod: string }) => {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "INTERNAL_SERVER_ERROR",
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
message: "Errore query getAnnuncio: " + (e as Error).message,
|
message: "Errore query getAnnunciMetaByCod: " + (e as Error).message,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue