add Sentry.captureException to catch blocks
This commit is contained in:
parent
7b6775c0fd
commit
00db95efd8
|
@ -1,4 +1,5 @@
|
|||
import { GetStaticProps } from 'next';
|
||||
import * as Sentry from '@sentry/nextjs';
|
||||
import {
|
||||
createClient,
|
||||
Profession,
|
||||
|
@ -17,7 +18,6 @@ import AboutExam from './components/AboutExam/AboutExam';
|
|||
import ExamParts from './components/ExamParts/ExamParts';
|
||||
import CheckMobileApp from './components/CheckMobileApp/CheckMobileApp';
|
||||
import Professions from './components/Professions/Professions';
|
||||
import * as Sentry from '@sentry/nextjs';
|
||||
|
||||
interface IndexPageProps {
|
||||
professions: Profession[];
|
||||
|
@ -77,7 +77,9 @@ export const getStaticProps: GetStaticProps = async () => {
|
|||
resp.professions.items
|
||||
);
|
||||
}
|
||||
} catch (e) {}
|
||||
} catch (e) {
|
||||
Sentry.captureException(e);
|
||||
}
|
||||
|
||||
return {
|
||||
props: pageProps,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { GetStaticPaths, GetStaticProps } from 'next';
|
||||
import * as Sentry from '@sentry/nextjs';
|
||||
import { isString, isNil } from 'lodash';
|
||||
import { polishPlurals } from 'polish-plurals';
|
||||
import {
|
||||
|
@ -58,74 +59,77 @@ const SUGGESTIONS_LIMIT = 6;
|
|||
const REVALIDATE_ERROR = 600;
|
||||
const REVALIDATE_SUCCESS = 10;
|
||||
|
||||
export const getStaticProps: GetStaticProps<
|
||||
TestPageProps,
|
||||
TestPageParams
|
||||
> = async ({ params }) => {
|
||||
const props: TestPageProps = {
|
||||
suggestions: [],
|
||||
questions: [],
|
||||
qualification: {
|
||||
id: 0,
|
||||
slug: '',
|
||||
name: '',
|
||||
code: '',
|
||||
createdAt: new Date(0),
|
||||
},
|
||||
export const getStaticProps: GetStaticProps<TestPageProps, TestPageParams> =
|
||||
async ({ params }) => {
|
||||
const props: TestPageProps = {
|
||||
suggestions: [],
|
||||
questions: [],
|
||||
qualification: {
|
||||
id: 0,
|
||||
slug: '',
|
||||
name: '',
|
||||
code: '',
|
||||
createdAt: new Date(0),
|
||||
},
|
||||
};
|
||||
|
||||
if (!params || isNil(params.limit) || !isString(params.slug))
|
||||
return { notFound: true, revalidate: REVALIDATE_ERROR };
|
||||
const limit = parseInt(params.limit);
|
||||
const slug = params.slug.trim();
|
||||
if (
|
||||
isNaN(limit) ||
|
||||
!QUESTIONS.some(numOfQuestions => numOfQuestions === limit)
|
||||
) {
|
||||
return {
|
||||
props,
|
||||
redirect: {
|
||||
destination: resolveAs({
|
||||
pathname: Route.TestPage,
|
||||
query: { ...params, limit: QUESTIONS[QUESTIONS.length - 1] },
|
||||
}),
|
||||
},
|
||||
revalidate: REVALIDATE_ERROR,
|
||||
};
|
||||
}
|
||||
|
||||
const client = createClient();
|
||||
try {
|
||||
const { qualification } = await client.request<
|
||||
Pick<Query, 'qualification'>,
|
||||
QueryQualificationArgs
|
||||
>(QUERY_QUALIFICATION, { slug });
|
||||
if (!qualification) {
|
||||
throw new Error('Qualification not found: slug=' + slug);
|
||||
}
|
||||
props.qualification = qualification;
|
||||
|
||||
const { generateTest, similarQualifications } = await client.request<
|
||||
Pick<Query, 'generateTest' | 'similarQualifications'>,
|
||||
QueryGenerateTestSimilarQualificationsArgs
|
||||
>(QUERY_GENERATE_TEST_SIMILAR_QUALIFICATIONS, {
|
||||
limitSuggestions: SUGGESTIONS_LIMIT,
|
||||
qualificationID: qualification.id,
|
||||
limitTest: limit,
|
||||
skipSuggestions: false,
|
||||
});
|
||||
|
||||
if (Array.isArray(generateTest)) {
|
||||
props.questions = generateTest;
|
||||
}
|
||||
|
||||
if (Array.isArray(similarQualifications.items)) {
|
||||
props.suggestions = similarQualifications.items;
|
||||
}
|
||||
|
||||
return {
|
||||
props,
|
||||
revalidate: REVALIDATE_SUCCESS,
|
||||
};
|
||||
} catch (e) {
|
||||
Sentry.captureException(e);
|
||||
return { notFound: true, revalidate: REVALIDATE_ERROR };
|
||||
}
|
||||
};
|
||||
|
||||
if (!params || isNil(params.limit) || !isString(params.slug))
|
||||
return { notFound: true, revalidate: REVALIDATE_ERROR };
|
||||
const limit = parseInt(params.limit);
|
||||
const slug = params.slug.trim();
|
||||
if (
|
||||
isNaN(limit) ||
|
||||
!QUESTIONS.some(numOfQuestions => numOfQuestions === limit)
|
||||
) {
|
||||
return {
|
||||
props,
|
||||
redirect: {
|
||||
destination: resolveAs({
|
||||
pathname: Route.TestPage,
|
||||
query: { ...params, limit: QUESTIONS[QUESTIONS.length - 1] },
|
||||
}),
|
||||
},
|
||||
revalidate: REVALIDATE_ERROR,
|
||||
};
|
||||
}
|
||||
|
||||
const client = createClient();
|
||||
try {
|
||||
const { qualification } = await client.request<
|
||||
Pick<Query, 'qualification'>,
|
||||
QueryQualificationArgs
|
||||
>(QUERY_QUALIFICATION, { slug });
|
||||
if (!qualification) {
|
||||
throw new Error('404');
|
||||
}
|
||||
props.qualification = qualification;
|
||||
const { generateTest, similarQualifications } = await client.request<
|
||||
Pick<Query, 'generateTest' | 'similarQualifications'>,
|
||||
QueryGenerateTestSimilarQualificationsArgs
|
||||
>(QUERY_GENERATE_TEST_SIMILAR_QUALIFICATIONS, {
|
||||
limitSuggestions: SUGGESTIONS_LIMIT,
|
||||
qualificationID: qualification.id,
|
||||
limitTest: limit,
|
||||
skipSuggestions: false,
|
||||
});
|
||||
if (Array.isArray(generateTest)) {
|
||||
props.questions = generateTest;
|
||||
}
|
||||
if (Array.isArray(similarQualifications.items)) {
|
||||
props.suggestions = similarQualifications.items;
|
||||
}
|
||||
return {
|
||||
props,
|
||||
revalidate: REVALIDATE_SUCCESS,
|
||||
};
|
||||
} catch (e) {
|
||||
return { notFound: true, revalidate: REVALIDATE_ERROR };
|
||||
}
|
||||
};
|
||||
|
||||
export default TestPage;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { Fragment, useRef, useState } from 'react';
|
||||
import { useUpdateEffect } from 'react-use';
|
||||
import * as Sentry from '@sentry/nextjs';
|
||||
import clsx from 'clsx';
|
||||
import { usePrompt } from 'libs/hooks';
|
||||
import {
|
||||
|
@ -97,6 +98,7 @@ const Test = ({ initialQuestions, qualification }: TestProps) => {
|
|||
|
||||
try {
|
||||
setIsFetching(true);
|
||||
|
||||
const { generateTest: newQuestions } = await createClient().request<
|
||||
Pick<Query, 'generateTest'>,
|
||||
QueryGenerateTestSimilarQualificationsArgs
|
||||
|
@ -106,8 +108,11 @@ const Test = ({ initialQuestions, qualification }: TestProps) => {
|
|||
skipSuggestions: true,
|
||||
qualificationID: qualification.id,
|
||||
});
|
||||
|
||||
resetValues(newQuestions);
|
||||
} catch (e) {}
|
||||
} catch (e) {
|
||||
Sentry.captureException(e);
|
||||
}
|
||||
|
||||
setIsFetching(false);
|
||||
};
|
||||
|
|
Reference in New Issue