JSON結果を返すときにコントローラーでエラーを処理するための最良の方法を探しています。
まず、コントローラーで未処理の例外が発生し、JSON を返す場合のベスト プラクティスは何でしょうか? 400または500エラーだと思いますか?クライアントはステータスをチェックし、何でもします。
FilterAttribute と IExceptionFilter で遊んでいますが、OnException 関数を呼び出すことができません。コントローラー アクションに属性を適用しました。
それが呼び出されない理由はありますか?
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public sealed class AjaxHandleErrorAttribute : FilterAttribute, IExceptionFilter
{
    // This is never called !!!
    public void OnException(ExceptionContext filterContext)
    {
        if (filterContext == null)
        {
            throw new ArgumentNullException("filterContext");
        }
        if (filterContext.Exception != null 
            && !filterContext.ExceptionHandled)
        {
            ...
            filterContext.HttpContext.Response.StatusCode = 400;
            filterContext.HttpContext.Response.StatusDescription = "Error processing                 request";
            ...
        }
    }
}
public class MyController : Controller
{
    public MyController(IMyRepository repo)
    {
        ...
    }
    [AjaxHandleError]
    public ActionResult GetSomeJson(int anId)
    {
        throw new System.Exception();
    }
}