How to set a specific Http status code when making a request for a specific HTML page using AngularJS

Is there a method in Angular to intentionally set an http status code after requesting a specific html page?

I am looking for a way to generate a 404 status when accessing a page with a particular URL, like: https://www.example.com/path/path?query=3.com

Answer №1

Not too sure if it's possible to extract the requested URL from the response within an $http interceptor.

You can attempt this by:

myModule.factory('myHttpInterceptor', function ($q) {
    return {
        response: function (response) {
            if (response.url === "http://test.com")
               response.status = 404;
            return response;
        }
    };
});


myModule.config(function ($httpProvider) {
    $httpProvider.interceptors.push('myHttpInterceptor');
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Looking to add tiered custom attribute select boxes in SnipCart - how can I make it happen?

I am interested in implementing two custom attributes for products, where the options for the second custom attribute are determined by the selection of the first attribute. My specific situation involves selling art in various formats and sizes, with dif ...

Converting a decimal Unicode to a string in Javascript/Node: a beginner's guide

In my database, I have Arabic sentences that contain decimal unicodes for quotation marks and other elements. For example, here is a sample text: "كريم نجار: تداعيات “كورونا” ستغير مستقبل سوق السي ...

Is the response of the post not being received?

here is an example of HTML code: <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="js/input.js"></script> </head> <body> <form> <ta ...

"Converting domain names with punycode and utilizing Firebase for a

My current project involves updating a Firebase app with NextJS, and I've encountered an issue that needs to be resolved. Upon running the command: % npm run build I received the following message: (node:3719) [DEP0040] DeprecationWarning: The `pun ...

Unraveling the operations of Node.js in its http.createServer method

I can't wrap my head around createServer in Node.js. This specific part of the code is really giving me trouble. http.createServer((req, res) => { let viewUrl = getViewUrl(req.url); fs.readFile(viewUrl, (error, data) => { if (error) { ...

Adjust the width of the table to scroll horizontally and size down to fit within the

My webpage is structured with a sidebar and content section, using flex display with the sidebar set to 0.15 flex and the content set to 0.85 flex. I want this page to be full width of the viewport. The issue arises when I try to incorporate a table into ...

Enhance the functionality of your Angular templates by utilizing filters to showcase object or model properties that may not be functioning

Here is what I have: // The key has the format "first.second.third"; // splitString function returns the part after the last ".". {{object.eventMap[key|splitString:'.':-1]}} is not functioning correctly. This code is within an ng-repeat, so it ...

An error has occurred: The transport specified is invalid and must be an object containing a log method

Issue: I am facing a problem while trying to run the node server.js file to execute a port listening http_server. It seems like the code is not working properly. Can someone please help me resolve this issue? var socket = require('socket.io'), ...

Issue with CSS files in Jest"errors"

I'm currently facing an issue while trying to pass my initial Jest Test in React with Typescript. The error message I am encountering is as follows: ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){.App ...

problem arising from the origin preventing me from utilizing localStorage in conjunction with JSDOM

Currently, I am facing an issue while trying to load a webpage in a node environment using JSDOM. The webpage relies on localStorage for its functionality. I have attempted to load the webpage by utilizing JSDOM's URL configuration option and accessi ...

What is the jQuery syntax for targeting a specific element within an object?

Is there a way to access a sub element from $(this)? For instance, how can I specifically select a span element inside the this object? ...

Changing all object values to true with React useState

In a certain file, I have defined an object with the following structure: export const items = { first: false, second: false, third: false } Within a component, I am using this object as shown below: import { items } from 'file'; const [el ...

My database images are not appearing, instead, blank bootstrap cards are displayed on the

I have set up an online store website with nodejs, express, and mongodb where I have stored image URLs, titles, descriptions in my database. However, the issue is that there are 2 black cards appearing before each image on the webpage. Below is the code sn ...

What is the process for accepting user input if their username remains the same?

I've been grappling with what logic to implement in this scenario. I want the user to be able to update their information, but an issue has arisen. What if a user wishes to change their email but keep the same username? As it stands, the username is ...

Arrange the column according to the property I am sending to a Cell

Header: "Votes", accessor: "Voter", filterable: false, Cell: row => <Voter id={row.index} vote={this.filterCount(row.index)} />, sortMethod: null //sort based on vote prop passed above ^ I am trying to sort my tabl ...

How can I handle returning different types of Observables in my Angular application?

I can't seem to get an observable to return properly. The mergeMap function inside my code doesn't appear to be executing at all. Here are the relevant snippets of code: book.service.ts import {HttpClient, HttpHeaders} from '@angular/comm ...

Utilizing Angular's globally accessible variables

As we make the switch to Angular.js for our webapp, we are faced with the challenge of storing global data. In the past, we used a global object called app to store various functions and variables that needed to be accessed across different parts of the ap ...

Issue: Module "expose?Zone!zone.js" could not be located

Just started experimenting with Angular 2 and encountering an issue when importing zone.js as a global variable: https://i.stack.imgur.com/gUFGn.png List of my packages along with their versions: "dependencies": { "angular2": "2.0.0-beta.3", "es ...

What is the process for combining JSON objects using the "id" key as the basis for merging

Having this json structure, my goal is to merge it based on the articleId. [{ "articleId": "45", "isA": false, "flags": { "isDema": fals ...

Exploring the synergies between Angular Dragula and utilizing the $index property

Currently, I have implemented an ng-repeat of rows that can be rearranged using Angular Dragula. Despite successful drag-and-drop functionality, the $index in ng-repeat remains constant for each item even after reordering. The screenshot below depicts the ...