From 05c4dbaa9288275efefaab6a2b5ace78d1204beb Mon Sep 17 00:00:00 2001 From: Matti Nannt Date: Thu, 5 Oct 2023 16:46:30 +0200 Subject: [PATCH] chore: improve error logging in survey service (#958) * fix: improve error logging in survey service * expect error class in error logging --- packages/lib/survey/service.ts | 35 ++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/lib/survey/service.ts b/packages/lib/survey/service.ts index c77b937d6b..0d9cde0c72 100644 --- a/packages/lib/survey/service.ts +++ b/packages/lib/survey/service.ts @@ -99,6 +99,9 @@ export const getSurveyWithAnalytics = async (surveyId: string): Promise => { select: selectSurvey, }); } catch (error) { + if (error instanceof Error) { + console.error(error.message); + } if (error instanceof Prisma.PrismaClientKnownRequestError) { throw new DatabaseError("Database operation failed"); } @@ -192,6 +200,9 @@ export const getSurvey = async (surveyId: string): Promise => { const survey = ZSurvey.parse(transformedSurvey); return survey; } catch (error) { + if (error instanceof Error) { + console.error(error.message); + } if (error instanceof z.ZodError) { console.error(JSON.stringify(error.errors, null, 2)); // log the detailed error information } @@ -243,6 +254,9 @@ export const getSurveysByAttributeClassId = async (attributeClassId: string): Pr } return surveys; } catch (error) { + if (error instanceof Error) { + console.error(error.message); + } if (error instanceof z.ZodError) { console.error(JSON.stringify(error.errors, null, 2)); // log the detailed error information } @@ -277,6 +291,9 @@ export const getSurveysByActionClassId = async (actionClassId: string): Promise< } return surveys; } catch (error) { + if (error instanceof Error) { + console.error(error.message); + } if (error instanceof z.ZodError) { console.error(JSON.stringify(error.errors, null, 2)); // log the detailed error information } @@ -297,6 +314,9 @@ export const getSurveys = async (environmentId: string): Promise => { select: selectSurvey, }); } catch (error) { + if (error instanceof Error) { + console.error(error.message); + } if (error instanceof Prisma.PrismaClientKnownRequestError) { throw new DatabaseError("Database operation failed"); } @@ -317,6 +337,9 @@ export const getSurveys = async (environmentId: string): Promise => { } return surveys; } catch (error) { + if (error instanceof Error) { + console.error(error.message); + } if (error instanceof z.ZodError) { console.error(JSON.stringify(error.errors, null, 2)); // log the detailed error information } @@ -353,6 +376,9 @@ export const getSurveysWithAnalytics = async (environmentId: string): Promise): Promise