1
0
Fork 0

XhrHttpImpl: throw {=>Http}Error

* src/dapi/http/XhrHttpImpl.js (serveError): Throw HttpError instead
  of Error.
* test/dapi/http/XhrHttpImplTest.js: Test updated accordingly.
master
Mike Gerwitz 2017-06-13 10:26:26 -04:00
parent a3e359a050
commit 624f35a489
2 changed files with 22 additions and 14 deletions

View File

@ -19,8 +19,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
var Class = require( 'easejs' ).Class,
HttpImpl = require( './HttpImpl' );
'use strict';
const Class = require( 'easejs' ).Class;
const HttpImpl = require( './HttpImpl' );
const HttpError = require( './HttpError' );
/**
@ -272,7 +275,7 @@ module.exports = Class( 'XhrHttpImpl' )
*/
'virtual protected serveError': function( req, callback )
{
var e = Error( req.status + " error from server" );
var e = HttpError( req.status + " error from server" );
e.status = req.status;
callback( e, req.responseText );

View File

@ -19,19 +19,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
var dapi = require( '../../../' ).dapi,
expect = require( 'chai' ).expect,
Class = require( 'easejs' ).Class,
HttpImpl = dapi.http.HttpImpl,
Sut = dapi.http.XhrHttpImpl,
'use strict';
DummyXhr = function()
const { expect } = require( 'chai' );
const { Class } = require( 'easejs' );
const {
HttpImpl,
XhrHttpImpl: Sut,
HttpError,
} = require( '../../../' ).dapi.http;
const DummyXhr = function()
{
this.open = function()
{
this.open = function()
{
DummyXhr.args = arguments;
};
DummyXhr.args = arguments;
};
};
describe( 'XhrHttpImpl', function()
@ -260,7 +265,7 @@ describe( 'XhrHttpImpl', function()
Sut( StubXhr )
.requestData( 'http://foo', 'GET', '', function( err, _ )
{
expect( err ).to.be.instanceOf( Error );
expect( err ).to.be.instanceOf( HttpError );
expect( err.message ).to.contain(
StubXhr.prototype.status