> ## Documentation Index
> Fetch the complete documentation index at: https://doc.lucidworks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# httpInterceptor

[localhost link]: http://localhost:3000/docs/4/app-studio/reference/services/lightning.httpInterceptor

[mintlify link]: https://doc.lucidworks.com/docs/4/app-studio/reference/services/lightning.httpInterceptor.md

[old doc.lw link]: https://doc.lucidworks.com/app-studio/4.2/1217.md

> [card] Key questions to get you started
>
> Powered by Lucidworks Agent Studio

## Description

Intercepts all `$http` requests that return with an error. It will then broadcast the event `httpInterceptorError`
which will provide the error object containing the status code, status text and other error information.

### Usage

```js wrap  theme={"dark"}
angular
module('myApp', ['lightning'] )
.* .run(['$rootScope', '$templateCache','$location','$timeout', function ($rootScope, $templateCache, $location,$timeout) {
$rootScope.$on('httpInterceptorError', function(event,error) {
    //File not found is HTML
    if(error.config.headers.Accept == 'text/html'){
        if(error.status == '404'){
            alert('Page Not Found!');
            //Timeout is required to redirect the page after all other events have fired
            $timeout(function(){
                $location.path('search');
            },0)
        }
    }
});
```

## Events

### httpInterceptorError

Broadcast the event `httpInterceptorError` when a `$http` request receives an error,
this will provide the error object containing the status code, status text and other error information.

#### Usage

```js wrap  theme={"dark"}
angular
module('myApp', ['lightning'] )
.* .run(['$rootScope', '$templateCache','$location','$timeout', function ($rootScope, $templateCache, $location,$timeout) {
$rootScope.$on('httpInterceptorError', function(event,error) {
//File not found is HTML
if(error.config.headers.Accept == 'text/html'){
if(error.status == '404'){
alert('Page Not Found!');
//Timeout is required to redirect the page after all other events have fired
$timeout(function(){
$location.path('search');
},0)
}
}
});
```

#### Type:

broadcast

#### Target:

root scope


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.