fix(error): add sanity checks before error destructuring

also preserve original stack trace(and print it) in dev mode
This commit is contained in:
zyachel
2024-08-23 03:16:05 +05:30
parent 333d3b107e
commit e320557add
16 changed files with 79 additions and 58 deletions

View File

@ -8,7 +8,7 @@ import Title from 'src/interfaces/shared/title';
import { AppError } from 'src/interfaces/shared/error';
import getOrSetApiCache from 'src/utils/getOrSetApiCache';
import title from 'src/utils/fetchers/title';
import { getProxiedIMDbImgUrl } from 'src/utils/helpers';
import { getErrorProperties, getProxiedIMDbImgUrl } from 'src/utils/helpers';
import { titleKey } from 'src/utils/constants/keys';
import styles from 'src/styles/modules/pages/title/title.module.scss';
@ -63,8 +63,8 @@ export const getServerSideProps: GetServerSideProps<Data, Params> = async ctx =>
const data = await getOrSetApiCache(titleKey(titleId), title, titleId);
return { props: { data, error: null, originalPath } };
} catch (error: any) {
const { message, statusCode } = error;
} catch (error) {
const { message, statusCode } = getErrorProperties(error);
ctx.res.statusCode = statusCode;
ctx.res.statusMessage = message;

View File

@ -6,7 +6,7 @@ import { BasicCard, Filters, Pagination, Reviews } from 'src/components/titleRev
import { AppError } from 'src/interfaces/shared/error';
import getOrSetApiCache from 'src/utils/getOrSetApiCache';
import { cursoredReviews } from 'src/utils/fetchers/titleReviews';
import { cleanQueryStr } from 'src/utils/helpers';
import { cleanQueryStr, getErrorProperties } from 'src/utils/helpers';
import { titleReviewsKey } from 'src/utils/constants/keys';
import styles from 'src/styles/modules/pages/titleReviews/titleReviews.module.scss';
import { TitleReviewsCursored } from 'src/interfaces/shared/titleReviews';
@ -60,8 +60,8 @@ export const getServerSideProps: GetServerSideProps<Data, Params> = async ctx =>
);
return { props: { data, error: null, originalPath } };
} catch (error: any) {
const { message, statusCode } = error;
} catch (error) {
const { message, statusCode } = getErrorProperties(error);
ctx.res.statusCode = statusCode;
ctx.res.statusMessage = message;

View File

@ -6,7 +6,7 @@ import { Filters, Pagination, Reviews, TitleCard } from 'src/components/titleRev
import { AppError } from 'src/interfaces/shared/error';
import getOrSetApiCache from 'src/utils/getOrSetApiCache';
import titleReviews from 'src/utils/fetchers/titleReviews';
import { cleanQueryStr, getProxiedIMDbImgUrl } from 'src/utils/helpers';
import { cleanQueryStr, getErrorProperties, getProxiedIMDbImgUrl } from 'src/utils/helpers';
import { titleReviewsKey } from 'src/utils/constants/keys';
import styles from 'src/styles/modules/pages/titleReviews/titleReviews.module.scss';
import TitleReviews from 'src/interfaces/shared/titleReviews';
@ -80,8 +80,8 @@ export const getServerSideProps: GetServerSideProps<Data, Params> = async ctx =>
);
return { props: { data, error: null, originalPath } };
} catch (error: any) {
const { message, statusCode } = error;
} catch (error) {
const { message, statusCode } = getErrorProperties(error);
ctx.res.statusCode = statusCode;
ctx.res.statusMessage = message;