Skip to content

Commit

Permalink
fix: client side errors from unexpected null/undefined values
Browse files Browse the repository at this point in the history
  • Loading branch information
mixu3 committed Mar 7, 2025
1 parent 55212aa commit a521efb
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const actionExtension: any = (
if (
!event ||
!trendCursor ||
!api ||
ecmodel.getOption().appKitChartId !== chartId ||
getTrendCursors(ecmodel).length > 4
)
Expand All @@ -47,7 +48,8 @@ export const actionExtension: any = (
registers.registerAction(
RemoveNearestTrendCursorActionType,
({ event, chartId }: RemoveTrendCursorAction, ecmodel, api) => {
if (!event || ecmodel.getOption().appKitChartId !== chartId) return;
if (!event || !api || ecmodel.getOption().appKitChartId !== chartId)
return;

const date = getXAxisDataValue(event.offsetX, api);

Expand All @@ -67,7 +69,12 @@ export const actionExtension: any = (
registers.registerAction(
CopyTrendCursorActionType,
({ event, chartId }: CopyTrendCursorAction, ecmodel, api) => {
if (!event || !chartId || ecmodel.getOption().appKitChartId !== chartId)
if (
!event ||
!chartId ||
!api ||
ecmodel.getOption().appKitChartId !== chartId
)
return;

const date = getXAxisDataValue(event.offsetX, api);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import {
TimeOrdering,
type BatchGetAssetPropertyAggregatesErrorEntry,
type BatchGetAssetPropertyAggregatesSuccessEntry,
type IoTSiteWiseServiceException,
AccessDeniedException,
InvalidRequestException,
ResourceNotFoundException,
} from '@aws-sdk/client-iotsitewise';
import { aggregateToDataPoint } from '../util/toDataPoint';
import { dataStreamFromSiteWise } from '../dataStreamFromSiteWise';
Expand Down Expand Up @@ -164,14 +168,20 @@ const sendRequest = ({
});
}
})
.catch((e) => {
Object.entries(callbackCache).forEach(([entryId, { onError }]) => {
onError({
entryId,
errorCode: e.$metadata?.httpStatusCode,
errorMessage: e.message,
.catch((e: IoTSiteWiseServiceException) => {
if (
e instanceof AccessDeniedException ||
e instanceof InvalidRequestException ||
e instanceof ResourceNotFoundException
) {
Object.entries(callbackCache).forEach(([entryId, { onError }]) => {
onError({
entryId,
errorCode: e.name,
errorMessage: e.message,
});
});
});
}
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import {
TimeOrdering,
type BatchGetAssetPropertyValueHistoryErrorEntry,
type BatchGetAssetPropertyValueHistorySuccessEntry,
type IoTSiteWiseServiceException,
AccessDeniedException,
InvalidRequestException,
ResourceNotFoundException,
} from '@aws-sdk/client-iotsitewise';
import { toDataPoint } from '../util/toDataPoint';
import { dataStreamFromSiteWise } from '../dataStreamFromSiteWise';
Expand Down Expand Up @@ -159,14 +163,20 @@ const sendRequest = ({
});
}
})
.catch((e) => {
Object.entries(callbackCache).forEach(([entryId, { onError }]) => {
onError({
entryId,
errorCode: e.$metadata?.httpStatusCode,
errorMessage: e.message,
.catch((e: IoTSiteWiseServiceException) => {
if (
e instanceof AccessDeniedException ||
e instanceof InvalidRequestException ||
e instanceof ResourceNotFoundException
) {
Object.entries(callbackCache).forEach(([entryId, { onError }]) => {
onError({
entryId,
errorCode: e.name,
errorMessage: e.message,
});
});
});
}
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import {
type IoTSiteWiseClient,
type BatchGetAssetPropertyValueErrorEntry,
type BatchGetAssetPropertyValueSuccessEntry,
type IoTSiteWiseServiceException,
AccessDeniedException,
InvalidRequestException,
ResourceNotFoundException,
} from '@aws-sdk/client-iotsitewise';
import { toDataPoint } from '../util/toDataPoint';
import { dataStreamFromSiteWise } from '../dataStreamFromSiteWise';
Expand Down Expand Up @@ -139,14 +143,20 @@ const sendRequest = ({
});
}
})
.catch((e) => {
Object.entries(callbackCache).forEach(([entryId, { onError }]) => {
onError({
entryId,
errorCode: e.$metadata?.httpStatusCode,
errorMessage: e.message,
.catch((e: IoTSiteWiseServiceException) => {
if (
e instanceof AccessDeniedException ||
e instanceof InvalidRequestException ||
e instanceof ResourceNotFoundException
) {
Object.entries(callbackCache).forEach(([entryId, { onError }]) => {
onError({
entryId,
errorCode: e.name,
errorMessage: e.message,
});
});
});
}
});
};

Expand Down

0 comments on commit a521efb

Please sign in to comment.