What's stopping the error exception from showing up on the client side?

Here's the scenario: I have an action method called SavePoint that contains some logic and throws a System.ArgumentException with the message "Error, no point found".

Additionally, there is an ajax function named saveFeature which makes a GET request to the url "/Feature/SavePoint", sending some JSON data. In case of success, it executes a callback function, and in case of error, it displays an alert with the thrown error.

The issue arises when trying to display the exception message "Error, no point found" using the thrownError parameter in the error handler of the ajax call. For some reason, thrownError turns out to be empty. Any thoughts on why the error message is not being displayed properly?

Answer №1

Jaromanda X and Brett Caswell provided an explanation for the "why" in their comments. Here is another way to approach it:

public IActionResult SavePoint(PointRequest point)
{
    try
    {
        //some logic
    }
    catch (Exception ex)
    {
        return BadRequest("Error, no point found");
    }
}

Alternatively, you can show the specific error message to the user:

public IActionResult SavePoint(PointRequest point)
{
    try
    {
        //some logic
    }
    catch (Exception ex)
    {
        return BadRequest($"Error, no point found. Message: {ex.InnerException.Message}");
    }
}

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

Discover the array of results by implementing a while loop in JavaScript

My goal is to create a list of outputs that are not evenly divisible by numbers smaller than the input value. For example, if the input value is 10, the list should be 10, 9, 8, 7, 6, 4, 3, 1. I have written some code in JavaScript for this purpose, but ...

What is the best way to utilize getInitialProps specifically during the building process of a NextJS site?

When I am developing a static site using NextJS, I need the getInitialProps method to run specifically during the build process and not when the client loads the page. During the build step, NextJS executes the getInitialProps method before generating the ...

Integrate CSS and Javascript Plugins into your Ruby on Rails application

I am utilizing an HTML, CSS, and JS template to design the interface for my Rails application. Within this template, there are several plug-ins that are required in both CSS and JS formats. I have stored these plug-ins within the "/assets/plugins/" directo ...

Click the button to automatically generate a serial number on the form

My form includes three input fields: sl no, stationerytype, and stationeryqty. By clicking the symbols + and -, I can add or delete these fields. I am attempting to automatically generate a Sl no in the sl no field when I click the plus symbol, and adjust ...

Converting an array into an object using Typescript and Angular

I have a service that connects to a backend API and receives data in the form of comma-separated lines of text. These lines represent attributes in a TypeScript class I've defined called TopTalker: export class TopTalker { constructor( pu ...

Clicking on a React Material UI ListItem

I am trying to develop a clickable country list with icons next to each ListItem. However, I am facing an issue where only one item can be selected at a time in a single click. Upon clicking a new item, the previously selected one gets deselected first. He ...

Is there a way to keep a div element anchored at the top of the page until I reach the bottom and then have it stick to the bottom as I continue

I have a question that I hope is clear enough! On my webpage, there is a div at the top that I want to move to the bottom when I scroll and reach the end of the page. Hopefully, you understand what I'm trying to achieve! If anyone has any ideas, I&ap ...

Using JavaScript build-in functions in a Vue template allows for enhanced functionality and

Is there a way to utilize JavaScript built-in functions within a Vue template? {{ eval(item.value.substring(2)) }} I attempted to use the JS function eval() in {{}}, but encountered several errors such as: [Vue warn]: Property or method "eval" i ...

Unable to display Flask jsonify in HTML using AJAX

I currently have three different forms displayed on one HTML page, and one of them is specifically for uploading a CSV file. The issue I am facing is that while this form successfully uploads the file to the server, the response from the server is not bein ...

Error encountered: Unable to access undefined properties while attempting to make an API call to AirTable using NextJS version 13.4

Currently in the process of learning how to use the App router with NextJS 13.4, I encountered an issue while attempting to make an external API call. Even though I am getting all the data correctly from Airtable, Next throws an error that disrupts my try ...

What could be causing the absence of any displayed content in FirBug when typing in the Google Search box?

Many websites with a suggestion box feature utilize AJAX requests to communicate with the server and receive responses. I attempted to intercept the requests made by the Google search box, but the FireBug console did not display anything. However, when us ...

Ways to apply the DirectCast operator within a specific data type

When incorporating the CType operator into a custom Type like the one below, the Type cannot be casted using the DirectCast operator: Public Structure ColorInfo ... Public Shared Widening Operator CType(ByVal colorInfo As ColorInfo) As Color ...

A step-by-step guide on accessing a JSON configuration file and configuring the parameter for AJAX requests

I have a configuration file named server.json which contains server details in JSON format. { "server": "127.0.0.1" } My objective is to retrieve the value of 'server' from this configuration file and use it in my jQuery functions. For exa ...

Problem with transitioning to a different page on Next.js

I am having trouble navigating to a different page in Next.js using the router.push function. The goal is to route to "example.js" by utilizing a variable called ChangePage, which leads to a single div element on that page. However, despite following the ...

Utilizing Async/Await with an Unassigned Object

I'm facing a puzzling issue with an async/await function that refuses to assign to an object. Despite displaying the expected results in the console, when it comes to actually assigning to the object, it fails to do so. Let me elaborate below: Here&a ...

Automatically fill in a text box with previously saved information

Does anyone have suggestions on how to create this type of textbox or what it is called? (View original image here) ...

An issue occurred while serializing or deserializing, specifically with the JavaScriptSerializer and

I am facing an issue while trying to retrieve images from my database. The process works smoothly with small images, but when attempting to do the same with the default Windows 7 images (Desert, Koala, Penguins, Tulips, etc.), I encounter an error: "Err ...

Invoke a component and initiate a click event from within the App.vue component

Within my template, there is a click event: <span v-on:click="showGalery()"> This event is linked to the following method: export default { name: 'osaka', data: function () { return { galery: false, } }, methods: { ...

Forget the function once it has been clicked

I'm looking for a solution to my resizing function issue. When I press a button, the function opens two columns outside of the window, but I want to reset this function when I click on another div. Is there a way to remove or clear the function from m ...

React Hamburger Menu not working as intended

I am facing an issue with my responsive hamburger menu. It is not functioning correctly when clicked on. The menu should display the navigation links and switch icons upon clicking, but it does neither. When I remove the line "{open && NavLink ...