fix: enhance error handling by including error messages in TRPCError responses

This commit is contained in:
Marco Pedone 2025-08-27 10:19:49 +02:00
parent babb798505
commit f20869d7fe

View file

@ -33,10 +33,10 @@ export const getAnnunciListHandler = async (): Promise<
"stato",
])
.execute();
} catch {
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Errore query getAllRaw",
message: "Errore query getAllRaw: " + (e as Error).message,
});
}
};
@ -54,10 +54,10 @@ export const getCodici_AnnunciHandler = async (): Promise<string[]> => {
}
return codici.map((c) => c.codice);
} catch {
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Errore query getCodici",
message: "Errore query getCodici: " + (e as Error).message,
});
}
};
@ -80,10 +80,10 @@ export const getAnnunciByCod = async ({
}
return AnnuncioObjectWithImages<typeof annuncio>(annuncio);
} catch {
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Errore query getAnnuncio",
message: "Errore query getAnnuncio: " + (e as Error).message,
});
}
};
@ -108,10 +108,10 @@ export const getAnnunciMetaByCod = async ({ cod }: { cod: string }) => {
description: annuncio.desc_it || "",
ogUrl: env.NEXT_PUBLIC_BASE_URL + "/annuncio/" + cod,
};
} catch {
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Errore query getAnnuncio",
message: "Errore query getAnnuncio: " + (e as Error).message,
});
}
};
@ -135,10 +135,10 @@ export const getAnnunciById = async ({
}
return AnnuncioObjectWithImages<typeof annuncio>(annuncio);
} catch {
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Errore query getAnnuncioById",
message: "Errore query getAnnuncioById : " + (e as Error).message,
});
}
};
@ -314,10 +314,10 @@ export const getCursor_AnnunciHandler = async ({
annunci,
hasMore,
};
} catch {
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Errore query getWithCursor",
message: "Errore query getWithCursor: " + (e as Error).message,
});
}
};
@ -344,10 +344,10 @@ export const getOptions_AnnunciHandler = async () => {
}
return results;
} catch {
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Errore query getComuni",
message: "Errore query getComuni: " + (e as Error).message,
});
}
};
@ -384,10 +384,10 @@ export const editAnnuncioHandler = async ({
.where("id", "=", annuncioId)
.execute();
return true;
} catch {
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Errore interno",
message: "Errore interno: " + (e as Error).message,
});
}
};