ASP.NET WebAPI のコントローラーの PUT アクション メソッド内で例外をスローする動作が、他のアクションや動詞の種類と異なる理由を知っている人はいますか?
基本的に、私は以下のコードを持っています (私は通常、例外フィルターをグローバルに登録していますが、それが原因ではないことを確認するためにそれを無効にしました)。
public class JourneysController : ApiController
{
private IJourneyRepository repository = null;
public JourneysController(IJourneyRepository repository)
{
this.repository = repository;
}
public async Task<Journey> GetById(string id)
{
throw new BusinessException("test1");
var item = await repository.Get(id);
if (item == null) throw new HttpResponseException(HttpStatusCode.NotFound);
return item;
}
public async Task<HttpResponseMessage> Post(HttpRequestMessage request, [FromBody]Journey value)
{
throw new BusinessException("test2");
value = await repository.Add(value);
var response = request.CreateResponse<Journey>(HttpStatusCode.Created, value);
string uri = Url.Link("DefaultApi", new { id = value.Id });
response.Headers.Location = new Uri(uri);
return response;
}
public async void Put(string id, [FromBody]Journey value)
{
throw new BusinessException("test3");
value.Id = id;
if (!await repository.Update(value)) throw new HttpResponseException(HttpStatusCode.NotFound);
}
public HttpResponseMessage Delete(string id)
{
throw new BusinessException("test4");
repository.Remove(id);
return new HttpResponseMessage(HttpStatusCode.NoContent);
}
}
(Chrome Advanced REST クライアントを使用して) GET、POST、および DELETE 動詞を実行すると、次のようなペイロードが得られます (クライアントからコピー/貼り付けする簡単な方法はありません)。
500 Internal Server Error
Date: Tue, 25 Sep 2012 15:37:56 GMT
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Length: 813
Pragma: no-cache
{
"Message": "An error has occurred.",
"ExceptionMessage": "test4",
"ExceptionType": "KieranBenton.LeaveNow.Services.Model.BusinessException",
"StackTrace": " <snip>"
}
ただし、PUT アクションは、次のような死亡ペイロードの黄色の画面を返します。
<span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
<h2> <i>test3</i> </h2></span>
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
<b> Exception Details: </b>KieranBenton.LeaveNow.Services.Model.BusinessException: test3
なぜこれが起こっているのか、または実際にバグに出くわしたのか、誰にもわかりませんか?
ありがとう。