메시지, 소스 및 스택 추적 값이 오버라이드 된 예외를 생성하는 데 도움을 줄 수 있습니까?웹 API의 사용자 정의 예외
HttpResponseMessage에서 httperror를 사용해 보았습니다.하지만 Stacktrace와 Source도 응답 예외에 추가해야합니다. 여기 내 코드는 다음과 같습니다
public Product GetProductById(int id)
{
var product = products.FirstOrDefault((p) => p.Id == id);
HttpResponseMessage errorResponse = null;
if (product == null)
{
//using httperror
var message = String.Format("Customer with id: {0} was not found", id);
var httpError = new HttpError(message);
errorResponse = Request.CreateErrorResponse(HttpStatusCode.NotFound, httpError);
throw new HttpResponseException(errorResponse);
}
return product;
}
출력 : { Message: "Customer with id: 7 was not found" }
사용자가 스택 추적을 볼 수 없어야합니다. –