Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8392507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:32:07+00:00 2026-06-09T19:32:07+00:00

I have an application built using AngularJS and a server-side backend that delivers all

  • 0

I have an application built using AngularJS and a server-side backend that delivers all requests in JSON form. Each and every request is wrapped in a JSON container that contains a data variable which contains the data specific to the request. The other data, which are used to keep state and control within the application, check for errors and success messages, and check for session flags. All of these other variables are served with EVERY request and are examined first before the data variable is.

Right now I have a method to examine the contents of the JSON response first and then the data itself.

$http.get('something.json').success(function(response) {
   var data = examineJSONResponse(response);
   //do the data stuff
});

This works and the examineJSONResponse takes a look at the code and if there is something wrong then it throws an exception and reloads the page using window.location.href.

Is there any way that I can automate this within AngularJS so that each time a $http call is made then it checks this and ONLY returns the data variable contents as the JSON response?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:32:08+00:00Added an answer on June 9, 2026 at 7:32 pm

    You can intercept responses by adding an interceptor to $httpProvider.interceptors with Angular 1.1.4+ (see documentation here search for interceptors).

    For a specific content type like json you can potentially reject changes or throw an exception even if the call was a success. You can modify the response.data that will get passed to your controller code as well here:

    myModule.factory('myHttpInterceptor', function ($q) {
        return {
            response: function (response) {
                // do something on success
                if(response.headers()['content-type'] === "application/json; charset=utf-8"){
                    // Validate response, if not ok reject
                    var data = examineJSONResponse(response); // assumes this function is available
    
                    if(!data)
                        return $q.reject(response);
                }
                return response;
            },
            responseError: function (response) {
                // do something on error
                return $q.reject(response);
            }
        };
    });
    myModule.config(function ($httpProvider) {
        $httpProvider.interceptors.push('myHttpInterceptor');
    });
    

    NOTE: Here is the original answer for versions prior to 1.1.4 (responseInterceptors were deprecated with Angular 1.1.4):

    Maybe there’s a better way but I think you can do something similar to this post with the http response interceptor (described here) (for a specific content type like json) where you potentially reject changes or throw an exception even though the call was a success. You can modify the response.data that will get passed to your controller code as well here.

    myModule.factory('myHttpInterceptor', function ($q) {
        return function (promise) {
            return promise.then(function (response) {
                // do something on success
                if(response.headers()['content-type'] === "application/json; charset=utf-8"){
                    // Validate response if not ok reject
                    var data = examineJSONResponse(response); // assumes this function is available
    
                    if(!data)
                        return $q.reject(response);
                }
                return response;
            }, function (response) {
                // do something on error
                return $q.reject(response);
            });
        };
    });
    myModule.config(function ($httpProvider) {
        $httpProvider.responseInterceptors.push('myHttpInterceptor');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application, built using MVC, that produces a view which delivers summary
All, I have a PHP Web application built using Zend Framework and MVC with
I have built a web application using Java EE platform that sells one of
I have an application built using PhoneGap (Android) that is essentially a shell for
We have an application that was built using .NET 3.5. There is a situation
I have an application that is built using ASP.NET, with an embedded Silverlight Object
I have a web application that needs to be built using PHP/MySQL. The application
I have a client/server application built using DataAbstract and RemObjects where the client is
I have an winforms application that was built using MVC. The controller is subscribing
I have an application built on Spring MVC that uses Hibernate for all of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.