-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FABN-1069: TimeoutError on commit event timeout
Allows calling code to distinguish between transaction invocation failure and a timeout waiting for a commit event following a successful transaction invocation. Timeout errors can be identified either by checking the error name or type: - error.name === 'TimeoutError' - error instanceof TimeoutError Change-Id: I9a58bde13fbe2e2271680d9f5441b1b1de1712a8 Signed-off-by: Mark S. Lewis <[email protected]>
- Loading branch information
1 parent
ca9b9d1
commit aa1236a
Showing
9 changed files
with
141 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright 2018 IBM All Rights Reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Base type for Fabric-specific errors. | ||
* @interface | ||
* @memberof module:fabric-network | ||
* @property {Error} [cause] Underlying error that caused this error. | ||
* @property {string} [transactionId] ID of the associated transaction. | ||
*/ | ||
class FabricError extends Error { | ||
/* | ||
* Constructor. | ||
* @param {(string|object)} [info] Either an error message (string) or additional properties to assign to this | ||
* inctance (object). | ||
*/ | ||
constructor(info) { | ||
if (!info || typeof info === 'string') { | ||
super(info); | ||
} else { | ||
super(info.message); | ||
Object.assign(this, info); | ||
} | ||
this.name = this.constructor.name; | ||
} | ||
} | ||
|
||
module.exports = FabricError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Copyright 2018 IBM All Rights Reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const FabricError = require('./fabricerror'); | ||
|
||
/** | ||
* Error indicating a timeout. | ||
* @extends module:fabric-network.FabricError | ||
* @memberof module:fabric-network | ||
*/ | ||
class TimeoutError extends FabricError { | ||
constructor(info) { | ||
super(info); | ||
} | ||
} | ||
|
||
module.exports = TimeoutError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright 2018 IBM All Rights Reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
|
||
const FabricError = require('fabric-network/lib/errors/fabricerror'); | ||
const TimeoutError = require('fabric-network/lib/errors/timeouterror'); | ||
|
||
describe('Common error behaviour', () => { | ||
[FabricError, TimeoutError].forEach((ErrorType) => describe(ErrorType.name, () => { | ||
it('name property matches class name', () => { | ||
const error = new ErrorType(); | ||
expect(error.name).to.equal(ErrorType.name); | ||
}); | ||
|
||
it('created with error message string', () => { | ||
const message = 'message'; | ||
const error = new ErrorType(message); | ||
expect(error.message).to.equal(message); | ||
}); | ||
|
||
it('created with error message property', () => { | ||
const info = {message: 'message'}; | ||
const error = new ErrorType(info); | ||
expect(error.message).to.equal(info.message); | ||
}); | ||
|
||
it('created with cause error', () => { | ||
const cause = new Error('cause'); | ||
const error = new ErrorType({cause}); | ||
expect(error.cause).to.equal(cause); | ||
}); | ||
|
||
it('associated with transaction ID', () => { | ||
const transactionId = 'txId'; | ||
const error = new ErrorType({transactionId}); | ||
expect(error.transactionId).to.equal(transactionId); | ||
}); | ||
|
||
it('name property does not override error name', () => { | ||
const error = new ErrorType({name: 'wrong'}); | ||
expect(error.name).to.equal(ErrorType.name); | ||
}); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters