Skip to content

Commit

Permalink
- BKNDLSS-24078 Transaction execution errors do not have a code
Browse files Browse the repository at this point in the history
  • Loading branch information
Valodya committed Jan 30, 2024
1 parent 18f184f commit dbd94c1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/unit-of-work/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { OpResult } from './op-result'
import { OpResultValueReference } from './op-result-value-reference'

class TransactionOperationError extends Error {
constructor(message, operation) {
super(message)
constructor(error, operation) {
super(error.message)

this.code = error.code
this.operation = operation
}

Expand Down Expand Up @@ -143,7 +144,7 @@ class UnitOfWork {
return result.error.operation.opResultId === op.meta.opResult.getOpResultId()
})

result.error = new TransactionOperationError(result.error.message, operation.meta.opResult)
result.error = new TransactionOperationError(result.error, operation.meta.opResult)

operation.meta.opResult.setError(result.error)
}
Expand Down
3 changes: 2 additions & 1 deletion test/unit/specs/transactions/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('<Transactions> Basic', function() {
opResultId : 'createPerson1',
operationType: 'CREATE',
payload : obj,
})
}, 1234)

const createOpResult = uow.create(PERSONS_TABLE_NAME, obj)

Expand All @@ -78,6 +78,7 @@ describe('<Transactions> Basic', function() {
expect(createOpResult.error).to.equal(createOpResult.getError())

expect(uowResult.error.operation).to.equal(createOpResult)
expect(uowResult.error.code).to.equal(1234)
})

it('converts a TransactionOperationError to JSON', async () => {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/specs/transactions/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ export function prepareSuccessResponse(results) {
}))
}

export function prepareErrorResponse(message, operation) {
export function prepareErrorResponse(message, operation, code) {
return prepareMockRequest(() => ({
body: {
success: false,
results: null,
error : {
message,
code,
operation
},
}
Expand Down

0 comments on commit dbd94c1

Please sign in to comment.