Reputation: 135
So I would like to get in console an json array with message, what would be equal with "Your direct manager have no account for your area."
But all I am getting is "Http failure response for https://localhost:44385/api/Option/Post: 500 Internal Server Error"
Note: When looking at dev tools -> network -> post -> response, then it shows html and css with right error message included, but no idea how to get it out from there.
Controller
[HttpPost("[action]")]
public void Post(Option option)
{
throw new NoBudgetAccountException();
}
Exception
[Serializable]
public class NoBudgetAccountException : Exception
{
public NoBudgetAccountException() : base("Your direct manager have no account for your area.")
{
}
}
Angular apiService
addOrUpdateOption(option: ITrainingOption): Observable<Response> {
return this.post<Response>("api/Option/Post", option);
}
Angular component
submitOption(option: ITrainingOption) {
this.apiService.addOrUpdateOption(option).subscribe(() => {
this.isAddOptionShown = false;
this.getHeadlines(this.selectedYear);
},
err => { console.log(err); });
}
Upvotes: 2
Views: 3773
Reputation: 344
usually with .net stuff when you do something like
throw new Exception("This is a custom exception");
It doesn't actually give you this message, instead it throws you an error html page
If you want to return a message and parse it in angular use an IActionResult instead and return BadRequest("message")
[HttpPost("[action]")]
public IActionResult test(Option option)
{
return BadRequest("This is an error message");
}
After doing this your error message should show in err.error
Upvotes: 3