I have my c# method , In the same I throwing exception in one of my case like below
throw new Exception("My Message");
And I am calling same endpoint from typescript , How can I get same message in typescript
When I am catching the exception in typescript like below code , I am not getting same message which is thrown in c#.
It is givingme standard internal server error .
catch(error => {
alert(error.response.data)
alert(error)


Rajeesh MenothRank #118 · 18.4K reputationPosted Feb 9, 2022, 4:42 AM EST
Arnab MukherjeeRank #879 · 2.5K reputationPosted Feb 9, 2022, 8:05 AM EST
Use a generic response class to simplify the communication model.
Try to return the response from your C# method with a proper status and message format,
so that you can check the status = sussess or error and you can receive a success and error message also.
{
status:"error"
message: "invalid exception."
}
Now, call the C# endpoint from typescript and you will receive the same message here.
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Feb 9, 2022, 6:34 AM EST
Mayur GujrathiRank #666 · 3.6K reputationPosted Feb 10, 2022, 5:23 AM EST