2016-08-13 7 views
0

:Angular2와 낸시 : 처리 오류 메시지 나 각도 2.</p> <p>내 낸시 서버 코드를 기반으로 웹 응용 프로그램에 낸시 오류 메시지에서 반환하려고

private dynamic GetSolution(dynamic arg) 
    { 
     string solutionName = arg.name; 

     if (solutionName == "error") 
     { 
      var response = Json(new {message = $"error"}); 
      response.StatusCode = HttpStatusCode.BadRequest; 
      return response; 
     } 

     return Json(solutionService.GetSolutionByName(solutionName)); 
    } 

클라이언트 측에서 다음과 프로세스 응답 코드 :

onButtonClicked(name: string): void 
{ 
    this 
     .solutionsService 
     .getSolutionByName(name) 
     .subscribe(
      p=>this.showMessage(p.title), 
      p=>this.showError(p.message)); 
    //this.refresh(true); 
} 

상태 (200) reponse는 경우 - 내가 예상 오브젝트 (필드 ID와 제목 솔루션을)받을 enter image description here

하지만 상태 코드 0 오류 (예 : 400) 내가 예상치 못한 개체를 얻을 경우 : 내가 잘못된 일을 enter image description here

?

답변

0

CORS 문제가 발생했습니다. 성공한 응답에서는 CORS 헤더를 응답에 추가했지만 잘못된 응답에서는 응답하지 않았습니다. Angular가 나를 돌아 오는 이유가 OPTIONS 비행 요청 이전에 응답하지 않았던 이유.