0

In the webservice the following Post call is made.

try{
User = await _service.Post<User>("api/authenticate", model);
}
catch(Exception ex){
Console.Writeline($"exception{ex.Message}");
}

In the Controller if the user name or password is wrong it results in a unauthorized.

return Unauthorized(new{message = "PW wrong"}) 

or the user object

return Ok(user);

The service is able to catch a

return BadRequest();

response but not the Unauthorized response.

I was wondering if their is a difference between those responses.

I tried already to use System.Net.WebException like in this answer on StackOverFlow question

Thanks in advance

Pearl
  • 39
  • 7
  • Http error codes don't throw exceptions You might want to go through this : https://stackoverflow.com/questions/21097730/usage-of-ensuresuccessstatuscode-and-handling-of-httprequestexception-it-throws – Mayur Ekbote Oct 16 '21 at 07:00
  • its weird because when i return badrequest it will be catched – Pearl Oct 17 '21 at 13:02

1 Answers1

0

throw a Custom JSON HTTP response error and catch it

Pearl
  • 39
  • 7