Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Parameters header #156

Merged
merged 1 commit into from
Aug 5, 2024
Merged
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
48 changes: 25 additions & 23 deletions src/server/ndjsonWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,31 @@ ndjsonWorker.process(async job => {
return;
}

const insertions = ndjsonResources
.trim()
.split(/\n/)
.map(async resourceStr => {
let data;
try {
data = JSON.parse(resourceStr);
} catch (e) {
throw new Error(`Error parsing JSON: ${resourceStr}`);
}
try {
checkSupportedResource(data.resourceType);
return updateResource(data.id, data, data.resourceType);
} catch (e) {
// Here, the location of the error message varies between standard error and ServerError
// The former path finds the message for a ServerError, the latter for a standard error
throw new Error(
`${data.resourceType}/${data.id} failed import with the following message: ${
e.issue?.[0]?.details?.text ?? e.message
}`
);
}
});
const ndjsonLines = ndjsonResources.trim().split(/\n/);
if (ndjsonLines.length > 0 && JSON.parse(ndjsonLines[0]).resourceType === 'Parameters') {
// check first line for a Parameters header and remove if necessary
ndjsonLines.shift();
}
const insertions = ndjsonLines.map(async resourceStr => {
let data;
try {
data = JSON.parse(resourceStr);
} catch (e) {
throw new Error(`Error parsing JSON: ${resourceStr}`);
}
try {
checkSupportedResource(data.resourceType);
return updateResource(data.id, data, data.resourceType);
} catch (e) {
// Here, the location of the error message varies between standard error and ServerError
// The former path finds the message for a ServerError, the latter for a standard error
throw new Error(
`${data.resourceType}/${data.id} failed import with the following message: ${
e.issue?.[0]?.details?.text ?? e.message
}`
);
}
});

const outcomes = await Promise.allSettled(insertions);

Expand Down
Loading