diff --git a/lib/model/query/entities.js b/lib/model/query/entities.js index 0358b4d9d..b350d3d80 100644 --- a/lib/model/query/entities.js +++ b/lib/model/query/entities.js @@ -13,7 +13,6 @@ const { equals, extender, unjoiner, page, markDeleted } = require('../../util/db const { map, mergeRight, pickAll } = require('ramda'); const { blankStringToNull, construct } = require('../../util/util'); const { QueryOptions } = require('../../util/db'); -const { getOrNotFound } = require('../../util/promise'); const { odataFilter } = require('../../data/odata-filter'); const { odataToColumnMap, parseSubmissionXml, getDiffProp, ConflictType } = require('../../data/entity'); const { isTrue } = require('../../util/http'); @@ -168,7 +167,8 @@ const _updateEntity = (dataset, entityData, submissionId, submissionDef, submiss const clientEntity = await Entity.fromParseEntityData(entityData); // validation happens here // Get version of entity on the server - const serverEntity = await Entities.getById(dataset.id, clientEntity.uuid).then(getOrNotFound); + const serverEntity = (await Entities.getById(dataset.id, clientEntity.uuid)) + .orThrow(Problem.user.entityNotFound({ entityUuid: clientEntity.uuid, datasetName: dataset.name })); let { conflict } = serverEntity; let conflictingProperties; // Maybe we don't need to persist this??? just compute at the read time diff --git a/lib/util/problem.js b/lib/util/problem.js index 0f5a2b247..2f268c282 100644 --- a/lib/util/problem.js +++ b/lib/util/problem.js @@ -155,6 +155,9 @@ const problems = { // dataset in submission does not exist datasetNotFound: problem(404.7, ({ datasetName }) => `The dataset (${datasetName}) specified in the submission does not exist.`), + // entity in submission does not exist + entityNotFound: problem(404.8, ({ entityUuid, datasetName }) => `The entity with UUID (${entityUuid}) specified in the submission does not exist in the dataset (${datasetName}).`), + // { allowed: [ acceptable formats ], got } unacceptableFormat: problem(406.1, ({ allowed }) => `Requested format not acceptable; this resource allows: ${allowed.join()}.`), diff --git a/test/integration/worker/entity.js b/test/integration/worker/entity.js index 3e8bd2ae5..4206d3eef 100644 --- a/test/integration/worker/entity.js +++ b/test/integration/worker/entity.js @@ -578,8 +578,8 @@ describe('worker: entity', () => { const event = await container.Audits.getLatestByAction('entity.error').then((o) => o.get()); event.actorId.should.equal(5); // Alice event.details.submissionId.should.equal(subEvent.details.submissionId); - event.details.errorMessage.should.equal('Could not find the resource you were looking for.'); - event.details.problem.problemCode.should.equal(404.1); + event.details.problem.problemCode.should.equal(404.8); + event.details.errorMessage.should.equal('The entity with UUID (12345678-1234-4123-8234-123456789abc) specified in the submission does not exist in the dataset (people).'); })); it('should fail for other constraint errors like dataset name does not exist', testService(async (service, container) => {