Identify and handle any HTTP errors that occur outside of the typical promise resolution or

Hi there,

I am currently working on calling an API from the back end using promises in Angular 8 with TypeScript. I am facing an issue where I am unable to receive the error response properly. Whenever I reject the error to get the response/error, I only receive "OK" as a message (msg = "OK"). However, in the console, I can see that there is actually a 500 error along with the response data. You can take a look at the code snippet and the response details in the network tab below:

getAllItem(id: number) {
let promise = new Promise((resolve, reject) => {
  this.http.post<any>(environment.apiEndPoint,
    { "Method": "myMethod"},
    Helper.getHeader()).toPromise().then((res: any) => {
      resolve(res);
    },
      msg => { reject(msg); });
});
return promise;

}

This is the actual response captured in the network tab:

{"Success": false, "ErrorCode": "SYSTEM909", "Data": {}}

In the network tab, you will see the following information: Status Code: 500

Thank you for your help!

Answer №1

Perhaps the issue lies with an interceptor that could be altering the error message. I suggest reviewing whether or not you have set up an interceptor.

Answer №2

Instead of using RxJS catchError, you can try handling errors differently

fetchItems(id: number) {
  return this.http.post(environment.apiEndPoint).pipe(
    onErrorResumeNext(error => { ... }) // alternative way to handle errors
  )
}

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

What is the correct way to fetch JSON data from a remote server using pure JavaScript?

I'm receiving JSON data from a remote server at openweathermap.org. Can anyone help me identify issues with my code? Here is an example of the server's response here var getWeatherJSON = function (city) { var httpRequest = window.XMLHttpRequ ...

Dropdown menu does not appear upon hovering over an item

I have been trying to create a menu that appears when hovering over #navigation-region. Below, you can see the HTML, CSS, and JavaScript code: The JavaScript is simply for adding the active class on the #navigation-region element. In the CSS, there is a s ...

Is your Typescript compilation running into a problem with jwt tokens?

Having issues while trying to compile a typescript file as the compiler is throwing an error message: Error: TS2339 - The property 'payload' does not exist on type 'string | object'. Property 'payload' does not exist on type ...

When a d3 event is triggered by clicking, the value should be saved in a textbox

After clicking the checkbox, I would like to have all the checked client IP values automatically populate a textbox within the div called "ip." Here is my code snippet: <html> <body> <div id="ipDiv"> Client_ip :<input ty ...

Error message: The 'event' variable is not defined in the Firebase function

I am in the process of creating an appointment application which includes a notification feature. I have integrated Firebase functions to send notifications to users when a new appointment is booked or canceled. However, I encountered an error that says Re ...

Is it possible to access XMLHTTPRequest.responseText using a standardized method in JSON.parse?

In my ASP.NET web application, I have a simple Javascript function that executes on an input's onblur event: function validateUsername() { var request = new XMLHttpRequest(); if (request == null) { alert("Failed to create request."); ...

Tips for displaying JSON data in HTML without the use of placeholder DIV elements

Customer Scenario: A user wants to search through Wikipedia. The search results should be limited to 5 articles, and the user should be able to view the title and introduction of each article. Developer Scenario: User input is provided via an HTML input f ...

How can a command in a test be executed that is located within a specific "section" in Nightwatch?

I've been utilizing nightwatch for my test automation. Within my page object, I have a "section" containing various commands. However, when attempting to call these commands in the test script, I encountered an error stating "section is not a function ...

Unexpected behavior detected in three.js and raycaster where conditional else statements fail to execute

I immersed myself into the world of three.js with the help of YouTube tutorials designed for beginners. One particular tutorial caught my eye where they showcased three spheres floating in space, each clickable. Inspired by that, I delved deeper into crea ...

Collaborative Artistry: Using HTML5, JavaScript, and Node.js for Multiplayer

Creating a multiplayer drawing application for touch-enabled devices has been a challenge. I have utilized Node.js with Socket.io to draw points on a canvas, but there's an issue with the touchend event not resetting properly. To illustrate, take a l ...

Monitoring a folder using webpack

Currently, I have webpack set up in my development environment to bundle all of my dependencies. To help concatenate various js files and include them in a script tag within the markup, I am utilizing the webpack-merge-and-include-globally plugin. Althoug ...

Navigating with React Router version 6 while implementing protected routes through the Context API

I have a setup that includes the following components: App.js import AppContext from './context/AppContext.js'; import router from './routes/routes.js'; function App() { const [token, setToken] = useState(""); f ...

Loading JavaScript variable with pre-processed JavaScript information

I have been working on loading test data into a javascript object and then passing it to my heating timers. While I have managed to make it work by individually inserting the code into each timer, I am looking to optimize my code and enhance my understandi ...

An error occurred stating 'TypeError: jsdom.jsdom is not a function' while using the paper-node.js in the npm paper module

Recently, I added the webppl-agents library to my project, including webppl and webppl-dp. However, when attempting to execute the command line test, I encountered some difficulties. It seems that there is a dependency problem with jsdom from the npm paper ...

Create a dynamic menu dropdown with absolute positioning using React

I recently made the transition to React and now I am in the process of converting my old vanillaJS website into ReactJS. One issue I am facing is with a button that is supposed to trigger the opening of a dropdown menu. <button type="button&qu ...

What could be causing Angular to not show the outcome? Why is it that only the complete-handler is being triggered?

Just wanted to share my current setup: ASP.NET Core 8 Web API .NET Core 8 backend for frontend Angular SPA served inside a bff using typescript (ES2022) Request flow: -> SPA (Cookie) -> BFF (Token) -> API Struggling with the SPA to display or i ...

Guide to executing a JS file using Selenium

Are there any methods to execute my JavaScript file using Selenium Web Driver? Is it possible for me to disable and re-enable a JS script in the Firefox browser while running tests? Currently, I configure preferences in the Firefox profile and initiate t ...

Accessing JSON file content from Firebase storage

I'm currently working on extracting the data from a JSON file stored in my Firebase in order to utilize it for searching within my Google action. So far, I have managed to retrieve the file, but I'm unsure of which method to employ next. I am loo ...

Unable to host static content with express

Currently, I am working with Jade and Express to serve static files. Below is the Express code I am using: app.use(express.static(__dirname + "/frontend")); Additionally, here is the Jade code within my layout.jade file: link(rel='stylesheet', ...