ASP.NET WebAPI의 컨트롤러에서 PUT 동작 메서드 내에서 예외를 throw하는 동작이 다른 동작 및 동사 유형과 다른 이유는 누구에게도 아는 사람이 있습니까? ?ASP.NET 웹 API '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);
}
}
내가 실행
는 GET, POST (크롬 고급 REST 클라이언트를 사용하여) 내가 (/ 복사 쉬운 방법은 클라이언트에서 붙여 넣기) 다음과 같은 페이로드를 얻을 동사를 삭제 :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>"
}
풋 동작이 나에게 같은 죽음의 페이로드의 노란색 화면을 돌려 그러나 :
<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
사람이 어떤 생각이 왜 일어나고 또는 실제로 버그를 우연히 발견 한 경우 수 있습니다이 가지고있다?
감사합니다.
큰 설명, 고마워요! –