Skip to content

Commit

Permalink
SK-1372 updated default value of continue on error
Browse files Browse the repository at this point in the history
  • Loading branch information
skyflow-bharti committed Jan 19, 2024
1 parent b9169bd commit eed8b27
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
31 changes: 27 additions & 4 deletions src/core-utils/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ export const getUpsertColumn = (tableName: string, options:Array<IUpsertOptions>
};
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);
Expand Down Expand Up @@ -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,
},
});
}
});
Expand Down Expand Up @@ -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);
},
Expand Down
7 changes: 5 additions & 2 deletions src/core/external/skyflow-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);

Check warning on line 189 in src/core/external/skyflow-container.ts

View check run for this annotation

Codecov / codecov/patch

src/core/external/skyflow-container.ts#L188-L189

Added lines #L188 - L189 were not covered by tests
} else resolve(insertedData);
},
);
Expand Down

0 comments on commit eed8b27

Please sign in to comment.