I have a controller, and a method as defined...
[HttpPost]
public ActionResult UpdateUser(UserInformation model){
// Instead of throwing exception
throw new InvalidOperationException("Something went wrong");
// I need something like
return ExecutionError("Error Message");
// which should be received as an error to my
// $.ajax at client side...
}
Problems with Exceptions
- We have to log exceptions in case of device or network errors like SQL Connectivity errors.
- These messages are like validation messages for users, we dont want to log.
- Throwing exceptions also floods Event Viewer.
I need some easy way to report some custom http status to my $.ajax call so that it should result an error at client side, but I do not want to throw an error.
UPDATE
I cannot change client script because it becomes inconsistent with other data source.
So far, HttpStatusCodeResult should work but it's IIS that is causing the problem here. No matter what error message I set, tried all answers, still I receive default message only.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…