import { SavedObject } from '../../types' ; import { SavedObjectsImportFailure , CreatedObject } from '../types' ; export function extractErrors ( savedObjectResults , savedObjectsToImport ) { const errors = [ ] ; const originalSavedObjectsMap = new Map < string , SavedObject < { title : string ; } > > ( ) ; for ( const savedObject of savedObjectsToImport ) { originalSavedObjectsMap . set ( `${ savedObject . type }:${ savedObject . id }` , savedObject ) ; } for ( const savedObject of savedObjectResults ) { if ( savedObject . error ) { const originalSavedObject = originalSavedObjectsMap . get ( `${ savedObject . type }:${ savedObject . id }` ) ; const title = originalSavedObject ?. attributes ?. title ; const { destinationId } = savedObject ; if ( savedObject . error . statusCode === 409 ) { errors . push ( { id : savedObject . id , type : savedObject . type , title , meta : { title } , error : { type : 'conflict' , ... ( destinationId && { destinationId } ) , } , } ) ; continue ; } errors . push ( { id : savedObject . id , type : savedObject . type , title , meta : { title } , error : { ... savedObject . error , type : 'unknown' , } , } ) ; } } return errors ; }