1
0
Fork 0

XhrHttpImpl no longer modifying response text

Status code included with error object
master
Mike Gerwitz 2015-05-28 12:07:28 -04:00
parent 8f9b8f779f
commit ca68d12370
2 changed files with 16 additions and 14 deletions

View File

@ -168,8 +168,10 @@ module.exports = Class( 'XhrHttpImpl' )
/** /**
* Serve an error response * Serve an error response
* *
* The default behavior is to return an Error and content containing the * The default behavior is to return an Error with the status code as a
* HTTP status and response text. * `status` property, and the original response text as the output
* value; the philosophy here is that we should never modify the output,
* since a certain format may be expected as the result.
* *
* When overriding this method, keep in mind that it should always * When overriding this method, keep in mind that it should always
* return an Error for the first argument, or set it to null, indicating * return an Error for the first argument, or set it to null, indicating
@ -187,12 +189,9 @@ module.exports = Class( 'XhrHttpImpl' )
*/ */
'virtual protected serveError': function( req, callback ) 'virtual protected serveError': function( req, callback )
{ {
callback( var e = Error( req.status + " error from server" );
Error( req.status + " error from server" ), e.status = req.status;
{
status: req.status, callback( e, req.responseText );
data: req.responseText
}
);
} }
} ); } );

View File

@ -136,7 +136,7 @@ describe( 'XhrHttpImpl', function()
* This is the default behavior, but can be changed by overriding * This is the default behavior, but can be changed by overriding
* the onLoad method. * the onLoad method.
*/ */
it( 'returns an error to the callback', function( done ) it( 'returns error to callback with status code', function( done )
{ {
var StubXhr = createStubXhr(); var StubXhr = createStubXhr();
StubXhr.prototype.status = 404; StubXhr.prototype.status = 404;
@ -145,29 +145,32 @@ describe( 'XhrHttpImpl', function()
.requestData( 'http://foo', 'GET', '', function( err, _ ) .requestData( 'http://foo', 'GET', '', function( err, _ )
{ {
expect( err ).to.be.instanceOf( Error ); expect( err ).to.be.instanceOf( Error );
expect( err.message ).to.contain( expect( err.message ).to.contain(
StubXhr.prototype.status StubXhr.prototype.status
); );
expect( err.status ).to.equal(
StubXhr.prototype.status
);
done(); done();
} ); } );
} ); } );
it( 'returns response text with error code', function( done ) it( 'returns response text as output', function( done )
{ {
var StubXhr = createStubXhr(), var StubXhr = createStubXhr(),
status = 404, status = 404,
reply = 'foobunny'; reply = 'foobunny';
StubXhr.prototype.status = status;
StubXhr.prototype.responseText = reply; StubXhr.prototype.responseText = reply;
Sut( StubXhr ) Sut( StubXhr )
.requestData( 'http://foo', 'GET', '', function( _, resp ) .requestData( 'http://foo', 'GET', '', function( _, resp )
{ {
expect( resp.status ).to.equal( status ); expect( resp ).to.equal( reply );
expect( resp.data ).to.equal( reply );
done(); done();
} ); } );
} ); } );