Skip to content

Commit

Permalink
Fix typos. Add status codes back to socket responses. Update CHANGELOG.
Browse files Browse the repository at this point in the history
  • Loading branch information
arobson committed Apr 27, 2015
1 parent d83eaa8 commit 9de2d3a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* Improve control over session and session cookie configuration
* Bug fix - socket.io adapter re-attached authentication middleware on every connection
* Minor improvement to logging abstraction and updates to specs still using debug
* Refactored module-level state out of http adapter
* Refactored module-level state out of http module
* Refactored module-level state out of modules
* Support object literal syntax for resource action handles
* Support custom error handling

## 0.3.x
Primary motivation here is to begin work on a version of autohost that will work well with a hypermedia library ( [hyped](https://github.com/leankit-labs/hyped) ). This is a breaking change because of several structural and naming changes to how resources get modeled.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"socket.io-client": "~1.3.5"
},
"scripts": {
"test": "gulp test"
"test": "gulp test-and-exit"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion spec/behavior/httpEnvelope.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ describe( 'HTTP Envelope', function() {
} );
} );

describe( 'with overriden render', function() {
describe( 'with overridden render', function() {
var envelope, req, res, request;
before( function() {
res = createResponse();
Expand Down
2 changes: 1 addition & 1 deletion spec/behavior/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe( 'Index', function() {
} );
} );

it( 'should use provided metronic instance', function() {
it( 'should use log configuration', function() {
log.config.should.eql( { fake: true } );
} );
} );
Expand Down
11 changes: 11 additions & 0 deletions spec/behavior/socketEnvelope.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe( 'Socket Envelope', function() {
socket.published.should.eql( [
{
success: false,
status: 500,
data: 'MyCustom: test'
}
] );
Expand Down Expand Up @@ -67,6 +68,7 @@ describe( 'Socket Envelope', function() {
socket.published.should.eql( [
{
success: false,
status: 404,
data: 'NEVER EVER'
}
] );
Expand Down Expand Up @@ -95,6 +97,7 @@ describe( 'Socket Envelope', function() {
socket.published.should.eql( [
{
success: false,
status: 401,
data: 'a test'
}
] );
Expand All @@ -116,6 +119,7 @@ describe( 'Socket Envelope', function() {
socket.published.should.eql( [
{
success: false,
status: 500,
data: 'no support'
}
] );
Expand All @@ -137,6 +141,7 @@ describe( 'Socket Envelope', function() {
socket.published.should.eql( [
{
success: true,
status: 200,
data: 'just a simple string'
}
] );
Expand All @@ -158,6 +163,7 @@ describe( 'Socket Envelope', function() {
socket.published.should.eql( [
{
success: true,
status: 202,
data: 'For me? Well I accept you!'
}
] );
Expand All @@ -179,6 +185,7 @@ describe( 'Socket Envelope', function() {
socket.published.should.eql( [
{
success: true,
status: 200,
data: { a: 1, b: 2, c: 3 }
}
] );
Expand All @@ -200,6 +207,7 @@ describe( 'Socket Envelope', function() {
socket.published.should.eql( [
{
success: true,
status: 200,
data: { a: 1, b: 2, c: 3 }
}
] );
Expand Down Expand Up @@ -231,6 +239,7 @@ describe( 'Socket Envelope', function() {
socket.published.should.eql( [
{
success: true,
status: 200,
data: { a: 1, b: 2, c: 3 },
_headers: {
h1: 'this is a header',
Expand Down Expand Up @@ -260,6 +269,7 @@ describe( 'Socket Envelope', function() {
socket.published.should.eql( [
{
success: false,
status: 400,
data: 'The API call \'test.forward\' is not supported via websockets. Sockets do not support proxying via forwardTo.'
}
] );
Expand Down Expand Up @@ -290,6 +300,7 @@ describe( 'Socket Envelope', function() {
socket.published.should.eql( [
{
success: false,
status: 400,
data: 'The resource you are trying to reach has moved.'
}
] );
Expand Down
12 changes: 9 additions & 3 deletions src/websocket/socketEnvelope.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ SocketEnvelope.prototype.forwardTo = function( /* options */ ) {
this.recordTime();
this.reply( {
success: false,
status: 400,
data: 'The API call \'' + this.topic + '\' is not supported via websockets. Sockets do not support proxying via forwardTo.'
} );
};
Expand All @@ -64,24 +65,28 @@ SocketEnvelope.prototype.recordTime = function() {

SocketEnvelope.prototype.redirect = function( /* options */ ) {
this.recordTime();
this.reply( { success: false, data: 'The resource you are trying to reach has moved.' } );
this.reply( {
success: false,
status: 400,
data: 'The resource you are trying to reach has moved.'
} );
throw new Error( 'Sockets do not support redirection.' );
};

SocketEnvelope.prototype.render = function( host, resource, action, result ) {
var envelope = { success: true, data: result };
var envelope = { success: true, status: 200, data: result };
if ( result.data || result.success ) {
_.merge( envelope, result );
}
if ( envelope.status > 100 && envelope.status < 300 ) {
envelope.success = true;
delete envelope.status;
}
this.reply( envelope );
};

SocketEnvelope.prototype.renderError = function( host, resource, action, error ) {
var defaultStrategy = {
status: 500,
body: error.message
};

Expand All @@ -97,6 +102,7 @@ SocketEnvelope.prototype.renderError = function( host, resource, action, error )

var reply = {
success: false,
status: strategy.status ? strategy.status : 500,
data: strategy.reply ? strategy.reply( error, this ) : strategy.body
};
this.reply( reply );
Expand Down

0 comments on commit 9de2d3a

Please sign in to comment.