add Sentry.captureException to catch blocks
This commit is contained in:
parent
7b6775c0fd
commit
00db95efd8
|
@ -1,4 +1,5 @@
|
||||||
import { GetStaticProps } from 'next';
|
import { GetStaticProps } from 'next';
|
||||||
|
import * as Sentry from '@sentry/nextjs';
|
||||||
import {
|
import {
|
||||||
createClient,
|
createClient,
|
||||||
Profession,
|
Profession,
|
||||||
|
@ -17,7 +18,6 @@ import AboutExam from './components/AboutExam/AboutExam';
|
||||||
import ExamParts from './components/ExamParts/ExamParts';
|
import ExamParts from './components/ExamParts/ExamParts';
|
||||||
import CheckMobileApp from './components/CheckMobileApp/CheckMobileApp';
|
import CheckMobileApp from './components/CheckMobileApp/CheckMobileApp';
|
||||||
import Professions from './components/Professions/Professions';
|
import Professions from './components/Professions/Professions';
|
||||||
import * as Sentry from '@sentry/nextjs';
|
|
||||||
|
|
||||||
interface IndexPageProps {
|
interface IndexPageProps {
|
||||||
professions: Profession[];
|
professions: Profession[];
|
||||||
|
@ -77,7 +77,9 @@ export const getStaticProps: GetStaticProps = async () => {
|
||||||
resp.professions.items
|
resp.professions.items
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
|
Sentry.captureException(e);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: pageProps,
|
props: pageProps,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { GetStaticPaths, GetStaticProps } from 'next';
|
import { GetStaticPaths, GetStaticProps } from 'next';
|
||||||
|
import * as Sentry from '@sentry/nextjs';
|
||||||
import { isString, isNil } from 'lodash';
|
import { isString, isNil } from 'lodash';
|
||||||
import { polishPlurals } from 'polish-plurals';
|
import { polishPlurals } from 'polish-plurals';
|
||||||
import {
|
import {
|
||||||
|
@ -58,74 +59,77 @@ const SUGGESTIONS_LIMIT = 6;
|
||||||
const REVALIDATE_ERROR = 600;
|
const REVALIDATE_ERROR = 600;
|
||||||
const REVALIDATE_SUCCESS = 10;
|
const REVALIDATE_SUCCESS = 10;
|
||||||
|
|
||||||
export const getStaticProps: GetStaticProps<
|
export const getStaticProps: GetStaticProps<TestPageProps, TestPageParams> =
|
||||||
TestPageProps,
|
async ({ params }) => {
|
||||||
TestPageParams
|
const props: TestPageProps = {
|
||||||
> = async ({ params }) => {
|
suggestions: [],
|
||||||
const props: TestPageProps = {
|
questions: [],
|
||||||
suggestions: [],
|
qualification: {
|
||||||
questions: [],
|
id: 0,
|
||||||
qualification: {
|
slug: '',
|
||||||
id: 0,
|
name: '',
|
||||||
slug: '',
|
code: '',
|
||||||
name: '',
|
createdAt: new Date(0),
|
||||||
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;
|
export default TestPage;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Fragment, useRef, useState } from 'react';
|
import { Fragment, useRef, useState } from 'react';
|
||||||
import { useUpdateEffect } from 'react-use';
|
import { useUpdateEffect } from 'react-use';
|
||||||
|
import * as Sentry from '@sentry/nextjs';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import { usePrompt } from 'libs/hooks';
|
import { usePrompt } from 'libs/hooks';
|
||||||
import {
|
import {
|
||||||
|
@ -97,6 +98,7 @@ const Test = ({ initialQuestions, qualification }: TestProps) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setIsFetching(true);
|
setIsFetching(true);
|
||||||
|
|
||||||
const { generateTest: newQuestions } = await createClient().request<
|
const { generateTest: newQuestions } = await createClient().request<
|
||||||
Pick<Query, 'generateTest'>,
|
Pick<Query, 'generateTest'>,
|
||||||
QueryGenerateTestSimilarQualificationsArgs
|
QueryGenerateTestSimilarQualificationsArgs
|
||||||
|
@ -106,8 +108,11 @@ const Test = ({ initialQuestions, qualification }: TestProps) => {
|
||||||
skipSuggestions: true,
|
skipSuggestions: true,
|
||||||
qualificationID: qualification.id,
|
qualificationID: qualification.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
resetValues(newQuestions);
|
resetValues(newQuestions);
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
|
Sentry.captureException(e);
|
||||||
|
}
|
||||||
|
|
||||||
setIsFetching(false);
|
setIsFetching(false);
|
||||||
};
|
};
|
||||||
|
|
Reference in New Issue