@@ -1457,12 +1457,17 @@ describe('errors', function() {
1457
1457
} ) ;
1458
1458
1459
1459
describe ( 'handling rejections' , function ( ) {
1460
+ var $exceptionHandler ;
1460
1461
var $httpBackend ;
1461
1462
var $resource ;
1462
1463
1463
1464
beforeEach ( module ( 'ngResource' ) ) ;
1465
+ beforeEach ( module ( function ( $exceptionHandlerProvider ) {
1466
+ $exceptionHandlerProvider . mode ( 'log' ) ;
1467
+ } ) ) ;
1464
1468
1465
- beforeEach ( inject ( function ( _$httpBackend_ , _$resource_ ) {
1469
+ beforeEach ( inject ( function ( _$exceptionHandler_ , _$httpBackend_ , _$resource_ ) {
1470
+ $exceptionHandler = _$exceptionHandler_ ;
1466
1471
$httpBackend = _$httpBackend_ ;
1467
1472
$resource = _$resource_ ;
1468
1473
@@ -1481,6 +1486,70 @@ describe('handling rejections', function() {
1481
1486
expect ( errorCb1 ) . toHaveBeenCalledOnce ( ) ;
1482
1487
expect ( errorCb2 ) . toHaveBeenCalledOnce ( ) ;
1483
1488
} ) ;
1489
+
1490
+
1491
+ it ( 'should report a PUR when no error callback or responseError interceptor is provided' ,
1492
+ function ( ) {
1493
+ var CreditCard = $resource ( '/CreditCard' ) ;
1494
+
1495
+ CreditCard . get ( ) ;
1496
+ $httpBackend . flush ( ) ;
1497
+
1498
+ expect ( $exceptionHandler . errors . length ) . toBe ( 1 ) ;
1499
+ expect ( $exceptionHandler . errors [ 0 ] ) . toMatch ( / ^ P o s s i b l y u n h a n d l e d r e j e c t i o n / ) ;
1500
+ }
1501
+ ) ;
1502
+
1503
+
1504
+ it ( 'should not report a PUR when an error callback or responseError interceptor is provided' ,
1505
+ function ( ) {
1506
+ var CreditCard = $resource ( '/CreditCard' , { } , {
1507
+ test1 : {
1508
+ method : 'GET'
1509
+ } ,
1510
+ test2 : {
1511
+ method : 'GET' ,
1512
+ interceptor : { responseError : function ( ) { return { } ; } }
1513
+ }
1514
+ } ) ;
1515
+
1516
+ // With error callback
1517
+ CreditCard . test1 ( noop , noop ) ;
1518
+ $httpBackend . flush ( ) ;
1519
+
1520
+ expect ( $exceptionHandler . errors . length ) . toBe ( 0 ) ;
1521
+
1522
+ // With responseError interceptor
1523
+ CreditCard . test2 ( ) ;
1524
+ $httpBackend . flush ( ) ;
1525
+
1526
+ expect ( $exceptionHandler . errors . length ) . toBe ( 0 ) ;
1527
+
1528
+ // With error callback and responseError interceptor
1529
+ CreditCard . test2 ( noop , noop ) ;
1530
+ $httpBackend . flush ( ) ;
1531
+
1532
+ expect ( $exceptionHandler . errors . length ) . toBe ( 0 ) ;
1533
+ }
1534
+ ) ;
1535
+
1536
+
1537
+ it ( 'should report a PUR when the responseError interceptor returns a rejected promise' ,
1538
+ inject ( function ( $q ) {
1539
+ var CreditCard = $resource ( '/CreditCard' , { } , {
1540
+ test : {
1541
+ method : 'GET' ,
1542
+ interceptor : { responseError : function ( ) { return $q . reject ( { } ) ; } }
1543
+ }
1544
+ } ) ;
1545
+
1546
+ CreditCard . test ( ) ;
1547
+ $httpBackend . flush ( ) ;
1548
+
1549
+ expect ( $exceptionHandler . errors . length ) . toBe ( 1 ) ;
1550
+ expect ( $exceptionHandler . errors [ 0 ] ) . toMatch ( / ^ P o s s i b l y u n h a n d l e d r e j e c t i o n / ) ;
1551
+ } )
1552
+ ) ;
1484
1553
} ) ;
1485
1554
1486
1555
describe ( 'cancelling requests' , function ( ) {
0 commit comments