Hi all,
Am having Employee class inthat there are two properties
1. Emp name
2. Empid
Am going to insert the details in db and returning employee class as response
Public async Task save data(employee request)
{
Try
{
Return await insertasync(request);
}
Catch(exception ex)
{
Return new employee();
}
Above codes return always 200 success code even if error occurs
How can I return 500 error response to the method
Can anyone let me know

Lokesh VarmanPosted Jul 8, 2023, 6:06 AM
To return a 500 error response in your code, you can modify the catch block to throw an exception with an appropriate HTTP status code. Here's an example:
Amit Kumar SinghPosted Jul 9, 2023, 5:15 AM
Hello,
Refer below link
https://code-maze.com/global-error-handling-aspnetcore/