サーバー側とクライアント側の両方でBreezeJを使用しています。次のコントローラーアクションがあります。製品コードが見つからない場合に404httpコードを取得したいと思います。
public Product GetProduct(string code)
{
var p = _contextProvider.Context.Products.Where(p => p.Code == code).FirstOrDefault();
if (p == null)
{
//does not work because because breeze swallows the exception
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return p;
}
以下はその回答です。HttpResponseExceptionはBreezeApiに飲み込まれます。何か案は?前もって感謝します。
{
"$id": "1",
"$type": "System.Web.Http.HttpError, System.Web.Http",
"Message": "An error has occurred.",
"ExceptionMessage": "Cannot perform runtime binding on a null reference",
"ExceptionType": "Microsoft.CSharp.RuntimeBinder.RuntimeBinderException",
"StackTrace": " at CallSite.Target(Closure , CallSite , Object )\r\n at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)\r\n at Breeze.WebApi.ODataActionFilter.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)\r\n at System.Web.Http.Filters.ActionFilterAttribute.CallOnActionExecuted(HttpActionContext actionContext, HttpResponseMessage response, Exception exception)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<>c__DisplayClass2.<System.Web.Http.Filters.IActionFilter.ExecuteActionFilterAsync>b__0(HttpResponseMessage response)\r\n at System.Threading.Tasks.TaskHelpersExtensions.<>c__DisplayClass41`2.<Then>b__40(Task`1 t)\r\n at System.Threading.Tasks.TaskHelpersExtensions.ThenImpl[TTask,TOuterResult](TTask task, Func`2 continuation, CancellationToken cancellationToken, Boolean runSynchronously)"
}