diff --git a/src/core-utils/collect.ts b/src/core-utils/collect.ts index 7b43f6e6..862b0a0e 100644 --- a/src/core-utils/collect.ts +++ b/src/core-utils/collect.ts @@ -33,8 +33,14 @@ export const getUpsertColumn = (tableName: string, options:Array }; export const constructInsertRecordRequest = ( records: IInsertRecordInput, - options: IInsertOptions = { tokens: true, continueOnError: true }, + options: IInsertOptions = { continueOnError: false, tokens: true }, ) => { + if (options.continueOnError === undefined) { + options = { + ...options, + continueOnError: false, + }; + } let requestBody: any = []; records.records.forEach((record) => { const upsertColumn = getUpsertColumn(record.table, options.upsert); @@ -113,9 +119,11 @@ export const constructInsertRecordResponseWithContinueOnError = (responseBody: a } } else { failedRecord.push({ - code: status, - description: `${body.error} - requestId: ${responseBody.requestId}`, - request_index: index, + error: { + code: status, + description: `${body.error} - requestId: ${responseBody.requestId}`, + request_index: index, + }, }); } }); @@ -276,12 +284,27 @@ export const insertDataInCollect = async ( options, finalInsertRecords.records, ); + if (insertResponse.records) { + insertResponse.records.forEach((record) => { + delete record.request_index; + }); + } } else { insertResponse = constructInsertRecordResponseWithContinueOnError( response, options, finalInsertRecords.records, ); + if (insertResponse.records) { + insertResponse.records.forEach((record) => { + delete record.request_index; + }); + } + if (insertResponse.errors) { + insertResponse.errors.forEach((errors) => { + delete errors.error.request_index; + }); + } } rootResolve(insertResponse); }, diff --git a/src/core/external/skyflow-container.ts b/src/core/external/skyflow-container.ts index 4f44f303..e543c3be 100644 --- a/src/core/external/skyflow-container.ts +++ b/src/core/external/skyflow-container.ts @@ -159,12 +159,12 @@ class SkyflowContainer { ...options, tokens: options?.tokens !== undefined ? options.tokens : true, continueOnError: options.continueOnError !== undefined - ? options.continueOnError : true, + ? options.continueOnError : false, }; } else { options = { tokens: true, - continueOnError: true, + continueOnError: false, }; } if (options?.upsert) { @@ -184,6 +184,9 @@ class SkyflowContainer { if (insertedData.error) { printLog(`${JSON.stringify(insertedData.error)}`, MessageType.ERROR, this.#context.logLevel); reject(insertedData.error); + } else if (insertedData.errors) { + printLog(`${JSON.stringify(insertedData.errors)}`, MessageType.ERROR, this.#context.logLevel); + reject(insertedData); } else resolve(insertedData); }, );