chore: improve error logging in survey service (#958)

* fix: improve error logging in survey service

* expect error class in error logging
This commit is contained in:
Matti Nannt
2023-10-05 16:46:30 +02:00
committed by GitHub
parent 09f885d365
commit 05c4dbaa92

View File

@@ -99,6 +99,9 @@ export const getSurveyWithAnalytics = async (surveyId: string): Promise<TSurveyW
select: selectSurveyWithAnalytics,
});
} catch (error) {
if (error instanceof Error) {
console.error(error.message);
}
if (error instanceof Prisma.PrismaClientKnownRequestError) {
throw new DatabaseError("Database operation failed");
}
@@ -132,7 +135,9 @@ export const getSurveyWithAnalytics = async (surveyId: string): Promise<TSurveyW
const survey = ZSurveyWithAnalytics.parse(transformedSurvey);
return survey;
} catch (error) {
console.error(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
}
@@ -172,6 +177,9 @@ export const getSurvey = async (surveyId: string): Promise<TSurvey | null> => {
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<TSurvey | null> => {
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<TSurvey[]> => {
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<TSurvey[]> => {
}
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<TS
select: selectSurveyWithAnalytics,
});
} catch (error) {
if (error instanceof Error) {
console.error(error.message);
}
if (error instanceof Prisma.PrismaClientKnownRequestError) {
throw new DatabaseError("Database operation failed");
}
@@ -381,6 +407,9 @@ export const getSurveysWithAnalytics = async (environmentId: string): Promise<TS
}
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
}
@@ -578,7 +607,9 @@ export async function updateSurvey(updatedSurvey: Partial<TSurvey>): Promise<TSu
return modifiedSurvey;
} catch (error) {
console.error(error);
if (error instanceof Error) {
console.error(error.message);
}
if (error instanceof Prisma.PrismaClientKnownRequestError) {
throw new DatabaseError("Database operation failed");
}