MCV AngularJS 응용 프로그램에 오류 처리를 구현하려고하지만이 문제를 해결할 방법이 확실하지 않습니다.콘텐츠 형식 응답이 포함 된 사용자 지정 오류 메시지
구조 내 AngularJS와에서
서비스 ticketService
내가 가지고있는 다음과 같은 방법 : 내가 백엔드 MVC 웹 API 메서드에서 반환 무엇
$scope.downloadFile = function (fileId) {
ticketService.downloadFile(fileId)
.then(function (response) {
// Handle correct request and response
}, function (err) {
// Handle error
notify({ message: "Something went wrong: " + err.data.Message, position: "center", duration: 10000 });
})
}
다음
가있다 :
this.downloadFile = function (fileId) {
return $http.get(baseUrl + "/Downloadfile/" + fileId, { responseType: "blob" });
}
그리고 내 컨트롤러에서
:var error = new HttpError("Failed to find file, bla bla bla.");
return Request.CreateResponse(HttpStatusCode.NotFound, error);
문제
내 문제는 내 responseType
이 blob
로 설정되어 있기 때문에, 내 err
객체가 동일한 응답 유형 것입니다. 내 백엔드 서비스가이 응답 유형을 무시하고 일부 Message
이 포함 된 객체로 응답 할 수 있어야한다고 믿습니다.
이 응답에서 나는 err.data.Message
을 얻을 수있을 것이라고 생각했지만이 시나리오를 오해했을 것입니까?
미리 감사드립니다.
API 메소드에서 "HttpResponseMessage"로 확인 했습니까? –
'HttpResponseMessage' 객체에 커스텀 메시지를 어떻게 적용하는지 모르겠습니다. 그것은 단지 내용에 있습니까? – Detilium
@BasantaMatia'HttpResponseMessage'는 나에게 같은 문제를 안겨다. 여전히 내 응답 유형 및 객체는 'Blob' 유형입니다 – Detilium