Skip to content

Commit

Permalink
Merge pull request #113 from juancoen/master
Browse files Browse the repository at this point in the history
#105 added a toggle to disabled prefixing error message with circuit name
  • Loading branch information
awolden committed May 8, 2019
2 parents 9b91c0b + 7c39587 commit 7252faa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ isOpen|N/A|boolean|Returns `true` if circuit is open
- **fallback**: function to call for fallback (can be defined also with calling `fallback` function)
- **isPromise**: `boolean` to opt out of check for callback in function. This affects the passed in function, health check and fallback
- **isFunction**: `boolean` to opt out of check for callback, always promisifying in function. This affects the passed in function, health check and fallback
- **modifyError**: modifies the error message by adding circuit name. default is true.

## Stats
Based on the `opts.statInterval` an event will be fired at regular intervals that contains a snapshot of the running state of the application.
Expand Down
3 changes: 2 additions & 1 deletion lib/Brakes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const defaultOptions = {
healthCheck: undefined,
fallback: undefined,
isFunction: false,
isPromise: false
isPromise: false,
modifyError: true
};

class Brakes extends EventEmitter {
Expand Down
2 changes: 1 addition & 1 deletion lib/Circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Circuit extends EventEmitter {
return this._brakes._fallback.apply(this, arguments);
}

if (err.message && this._brakes.name) {
if (err.message && this._brakes.name && this._brakes._opts.modifyError) {
err.message = `[Breaker: ${this._brakes.name}] ${err.message}`;
}

Expand Down
18 changes: 16 additions & 2 deletions test/Brakes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ const defaultOptions = {
healthCheck: undefined,
fallback: undefined,
isFunction: false,
isPromise: false
isPromise: false,
modifyError: true
};

const modifyError = function modifyError() {
throw new Error('Not found');
};

const noop = function noop(foo, err, cb) {
Expand Down Expand Up @@ -113,6 +118,14 @@ describe('Brakes Class', () => {
expect(err.message).to.equal('[Breaker: defaultBrake] err');
});
});
it('Should not prefix error messages', () => {
brake = new Brakes(modifyError, {
modifyError: false,
});
return brake.exec(null).then(null, err => {
expect(err.message).to.equal('Not found');
});
});

it('Should accept a promise', () => {
brake = new Brakes(nopr);
Expand Down Expand Up @@ -163,7 +176,8 @@ describe('Brakes Class', () => {
healthCheck: () => Promise.resolve(),
fallback: () => Promise.resolve(),
isFunction: false,
isPromise: false
isPromise: false,
modifyError: true
};
brake = new Brakes(noop, overrides);
expect(brake._opts).to.deep.equal(overrides);
Expand Down

0 comments on commit 7252faa

Please sign in to comment.