XhrHttpImpl no longer modifying response text
Status code included with error objectmaster
parent
8f9b8f779f
commit
ca68d12370
|
@ -168,8 +168,10 @@ module.exports = Class( 'XhrHttpImpl' )
|
|||
/**
|
||||
* Serve an error response
|
||||
*
|
||||
* The default behavior is to return an Error and content containing the
|
||||
* HTTP status and response text.
|
||||
* The default behavior is to return an Error with the status code as a
|
||||
* `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
|
||||
* 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 )
|
||||
{
|
||||
callback(
|
||||
Error( req.status + " error from server" ),
|
||||
{
|
||||
status: req.status,
|
||||
data: req.responseText
|
||||
}
|
||||
);
|
||||
var e = Error( req.status + " error from server" );
|
||||
e.status = req.status;
|
||||
|
||||
callback( e, req.responseText );
|
||||
}
|
||||
} );
|
||||
|
|
|
@ -136,7 +136,7 @@ describe( 'XhrHttpImpl', function()
|
|||
* This is the default behavior, but can be changed by overriding
|
||||
* 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();
|
||||
StubXhr.prototype.status = 404;
|
||||
|
@ -145,29 +145,32 @@ describe( 'XhrHttpImpl', function()
|
|||
.requestData( 'http://foo', 'GET', '', function( err, _ )
|
||||
{
|
||||
expect( err ).to.be.instanceOf( Error );
|
||||
|
||||
expect( err.message ).to.contain(
|
||||
StubXhr.prototype.status
|
||||
);
|
||||
|
||||
expect( err.status ).to.equal(
|
||||
StubXhr.prototype.status
|
||||
);
|
||||
|
||||
done();
|
||||
} );
|
||||
} );
|
||||
|
||||
|
||||
it( 'returns response text with error code', function( done )
|
||||
it( 'returns response text as output', function( done )
|
||||
{
|
||||
var StubXhr = createStubXhr(),
|
||||
status = 404,
|
||||
reply = 'foobunny';
|
||||
|
||||
StubXhr.prototype.status = status;
|
||||
StubXhr.prototype.responseText = reply;
|
||||
|
||||
Sut( StubXhr )
|
||||
.requestData( 'http://foo', 'GET', '', function( _, resp )
|
||||
{
|
||||
expect( resp.status ).to.equal( status );
|
||||
expect( resp.data ).to.equal( reply );
|
||||
expect( resp ).to.equal( reply );
|
||||
done();
|
||||
} );
|
||||
} );
|
||||
|
|
Loading…
Reference in New Issue