Skip to content

Commit

Permalink
fix: error handling fixes (#31)
Browse files Browse the repository at this point in the history
* error handling fixes

* marginy review fixes
  • Loading branch information
korvin89 authored Jul 27, 2022
1 parent 9118091 commit e20fb9d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
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() {
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;

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

0 comments on commit e20fb9d

Please sign in to comment.