Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error handling fixes #31

Merged
merged 2 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/ErrorBoundary/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ErrorBoundary extends React.Component<Props, State> {
error: undefined,
};

componentDidUpdate() {
componentDidCatch() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

componentDidCatch definitely invoked in case of error (unlike componentDidUpdate)

const {error} = this.state;

if (error) {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/chartkit-error/chartkit-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const CHARTKIT_ERROR_CODE = {

export class ChartKitError extends Error {
readonly code: number | string;
readonly isChartKitError = true;
readonly isCustomError = true;
Copy link
Collaborator Author

@korvin89 korvin89 Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To easier compatibility with old code in DL. It will be changed to isChartKitError later


constructor({
originalError,
Expand All @@ -31,5 +31,5 @@ export class ChartKitError extends Error {
}

export const isChartKitError = (error: unknown): error is ChartKitError => {
return error instanceof Error && 'isChartKitError' in error;
return error instanceof Error && 'isCustomError' in error;
};
5 changes: 3 additions & 2 deletions src/plugins/indicator/renderer/IndicatorWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import block from 'bem-cn-lite';
import {isEmpty} from 'lodash';
import {i18n} from '../../../i18n';
import {CHARTKIT_ERROR_CODE, ChartKitError} from '../../../libs';
import {CHARTKIT_SCROLLABLE_NODE_CLASSNAME} from '../../../constants';
Expand All @@ -18,14 +19,14 @@ const IndicatorWidget = React.forwardRef<ChartKitWidgetRef | undefined, Indicato
const {
onLoad,
formatNumber,
data: {data, defaultColor},
data: {data = [], defaultColor},
} = props;

React.useEffect(() => {
onLoad?.();
}, []);

if (!data) {
if (isEmpty(data)) {
throw new ChartKitError({
code: CHARTKIT_ERROR_CODE.NO_DATA,
message: i18n('error', 'label_no-data'),
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type ChartKitOnLoadData<T extends ChartkitType> = {

export type ChartKitOnError = (data: {error: any}) => void;

export type ChartKitFormatNumber = (value: number, options?: unknown) => string;
export type ChartKitFormatNumber = <T = any>(value: number, options?: T) => string;

export type ChartKitProps<T extends ChartkitType> = {
type: T;
Expand Down