Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #6 from turbonetix/add_ease
Browse files Browse the repository at this point in the history
READY: added an error method to the API
  • Loading branch information
NathanGRomano committed Jul 25, 2014
2 parents 204ff54 + 78815a1 commit 739fd5c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -477,6 +477,14 @@ to the socket will be halted.
controller.consume();
```

### Controller#errored(err:Error)

When processing a message you decide that you want to *respond* with an error simply call `errored`.

```javascript
controller.errored(new Error('Some Error'));
```

# Installation and Environment Setup

Install node.js (See download and install instructions here: http://nodejs.org/).
Expand Down
1 change: 1 addition & 0 deletions lib/builder.js
Expand Up @@ -33,6 +33,7 @@ util.inherits(Builder, events.EventEmitter);

'actor action target content id created reference published'.split(' ').forEach(function (name) {
Builder.prototype[name] = function () {
debug('delegating %s to the message instance', name);
var v = this.message[name].apply(this.message,slice.call(arguments));
if ('object' === typeof v && (v === this.message || v.isMessage)) {
return this;
Expand Down
21 changes: 20 additions & 1 deletion lib/controller.js
Expand Up @@ -99,14 +99,33 @@ Controller.prototype.deliver = function () {
return this;
};


/**
* This method is a conveince for setting the content and as well as triggering
* the response, if we encounter an error.
*
* @param {mixed} content
* @return Controller
*/

Controller.prototype.errored = function (err) {
debug('responding with an error');
this.action(this.action() + ' errored').respond(err);
return this;
};




/**
* set up delegates
*/

'actor action target content id created reference published'.split(' ').forEach(function (name) {
Controller.prototype[name] = function () {
debug('delegating %s to the message instance', name);
var v = this.message[name].apply(this.message,slice.call(arguments));
if (v === this.message) {
if ('object' === typeof v && (v === this.message || v.isMessage)) {
return this;
}
else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "bus.io-common",
"version": "0.1.2",
"version": "0.2.0",
"description": "The common components for bus.io",
"main": "index.js",
"scripts": {
Expand Down
9 changes: 9 additions & 0 deletions spec/lib/controller-spec.coffee
Expand Up @@ -107,6 +107,15 @@ describe 'Controller', ->
And -> expect(@controller.emit.argsForCall[2][1].created() instanceof Date).toBe true
And -> expect(@controller.message.delivered instanceof Date).toBe true

describe.only '#errored', ->

Given -> @err = 'Some Error'
Given -> spyOn(@controller,'action').andCallThrough()
Given -> spyOn(@controller,'respond')
When -> @controller.errored @err
Then -> expect(@controller.action).toHaveBeenCalledWith 'say errored'
And -> expect(@controller.respond).toHaveBeenCalledWith @err

describe '#actor (v:String="a")', ->

Given -> @v = 'a'
Expand Down

0 comments on commit 739fd5c

Please sign in to comment.