Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import React, { useCallback, useState } from 'react';
import {
ImportDataResponse,
ImportDataProps,
ImportRulesResponseError,
ImportResponseError,
} from '../../../detections/containers/detection_engine/rules';
import {
displayErrorToast,
Expand All @@ -48,6 +50,12 @@ interface ImportDataModalProps {
title: string;
}

const isImportRulesResponseError = (
error: ImportRulesResponseError | ImportResponseError
): error is ImportRulesResponseError => {
return (error as ImportRulesResponseError).rule_id !== undefined;
};

/**
* Modal component for importing Rules from a json file
*/
Expand Down Expand Up @@ -96,7 +104,11 @@ export const ImportDataModalComponent = ({
}
if (importResponse.errors.length > 0) {
const formattedErrors = importResponse.errors.map((e) =>
failedDetailed(e.rule_id, e.error.status_code, e.error.message)
failedDetailed(
isImportRulesResponseError(e) ? e.rule_id : e.id,
e.error.status_code,
e.error.message
)
);
displayErrorToast(errorMessage, formattedErrors, dispatchToaster);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,18 @@ export interface ImportRulesResponseError {
};
}

export interface ImportResponseError {
id: string;
error: {
status_code: number;
message: string;
};
}

export interface ImportDataResponse {
success: boolean;
success_count: number;
errors: ImportRulesResponseError[];
errors: Array<ImportRulesResponseError | ImportResponseError>;
}

export interface ExportDocumentsProps {
Expand Down