2016-10-20 5 views
1

정말 간단하게 들리려고 노력하고 있습니다. 내 application.hbs의 콘센트에 서버 오류를 렌더링하고 싶습니다.Ember + Ember 데이터, 처리 오류 하위 수준, Ember 2.8

이 문서를 읽고 https://guides.emberjs.com/v2.6.0/routing/loading-and-error-substates/, 내 오류를 감지 할 수 있지만 주어진 패턴을 따라 내 error.hbs 모델로 오류를 전달할 수 없습니다.

언급 한대로 응용 프로그램 경로에 오류 작업 처리기를 등록하면 error.hbs 서식 파일을 렌더링 할 수는 있지만 처리 할 오류 개체의 컨텍스트에 액세스 할 수 없습니다. 또한, 원하지 않는 URL 경로 업데이트가 발생합니다.

actions: { 
    error(err, transition) { 
     return this.transitionTo('error'); 
    } 
} 

이 핸들러를 사용하여 error.hbs를 콘센트에 렌더링하지만, 내 오류 개체에서 해당 템플릿을 렌더링하는 컨텍스트가 없습니다. 내가 모델로 오류를 전달하려고하면, 나는이 오류 얻을 : 오류가 모델을로드 발생할 때마다 지금

More context objects were passed than there are dynamic segments for the route: error 

을, 난 그냥 영원히 중단 로딩 스피너 상태를 얻는다. 대신 서버 오류를 표시하고 싶습니다.

답변

0

오류는 모델의 오류 substates로 전달됩니다. throw n 또는 reject ed 인 오브젝트는 오류 부속 모델의 속성이됩니다.

예를 들어 throw 또는 RSVP.reject{ message: 'An Error Occurred' } 인 경우 {{model.message}}을 사용하여 error.hbs에 표시 할 수 있습니다. 나는 throw/reject 프리미티브가 작동하는 것을 본 적이 없다.

Here is a twiddle that demonstrates working error substates (추가 사례를 보려면/거부 및/미정의 경로로드).

템플릿/응용 프로그램 error.hbs을 만지작 거릴 (도 될 수 error.hbs)에서

코드 throw.js

<p>Application-Error Template</p> 
<p>model: {{model}}</p> 
<p>model.message: {{model.message}}</p> 
<p>model.customMessage: {{model.customMessage}}</p> 

루트/

model(params) { 
    throw { customMessage: 'Reject Error Message' }; 
}, 

루트/거부 .js

model(params) { 
    return Ember.RSVP.reject({ customMessage: 'Reject Error Message' }); 
}, 

경로/정의되지 않음 .js

model(params) { 
    use.undefined.value; 
},