Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Custom Code - Page is in React Js

harpreets991202
Level 2
Level 2

Can you please let me know in which language custom code should be developed if page is in React js.

Harpreet

1 Accepted Solution
hariharans94469
Correct answer by
Level 3
Level 3

Hi Harpreet,

   I am also working in React pages. Currently I am using Plain Javascript to implement the test variants. In Angular 1.x version we can create a functionality using Angular. The below code for extending the interceptor. But in React we does not have the way to write custom code.

  angular.module('appModule').config(function ($httpProvider, $provide) {

    $provide.factory('httpInterceptor', function ($q, $rootScope) {

        return {

            'request': function (config) {

           

$rootScope.$broadcast('httpRequest', config);

                return config || $q.when(config);

            },

            'response': function (response) {

$rootScope.$broadcast('httpResponse', response);

                return response || $q.when(response);

            },

            'requestError': function (rejection) {

                $rootScope.$broadcast('httpRequestError', rejection);

                return $q.reject(rejection);

            },

            'responseError': function (rejection) {

$rootScope.$broadcast('httpResponseError', rejection);

                return $q.reject(rejection);

            }

        };

    });

$httpProvider.interceptors.push('httpInterceptor');

});

Thanks,

Hariharan S

View solution in original post

1 Reply
hariharans94469
Correct answer by
Level 3
Level 3

Hi Harpreet,

   I am also working in React pages. Currently I am using Plain Javascript to implement the test variants. In Angular 1.x version we can create a functionality using Angular. The below code for extending the interceptor. But in React we does not have the way to write custom code.

  angular.module('appModule').config(function ($httpProvider, $provide) {

    $provide.factory('httpInterceptor', function ($q, $rootScope) {

        return {

            'request': function (config) {

           

$rootScope.$broadcast('httpRequest', config);

                return config || $q.when(config);

            },

            'response': function (response) {

$rootScope.$broadcast('httpResponse', response);

                return response || $q.when(response);

            },

            'requestError': function (rejection) {

                $rootScope.$broadcast('httpRequestError', rejection);

                return $q.reject(rejection);

            },

            'responseError': function (rejection) {

$rootScope.$broadcast('httpResponseError', rejection);

                return $q.reject(rejection);

            }

        };

    });

$httpProvider.interceptors.push('httpInterceptor');

});

Thanks,

Hariharan S

View solution in original post