RSVP 내부에서 컨텍스트를 가져 오는 더러운 임시 해결책을 사용하고 있습니다. RVSP.Promise._onerror 메서드를 덮어 쓰고 일부 데이터를 포함 할 수 있습니다. 'this'객체에는 모델에 대한 유용한 정보가 들어있는 _label 속성이 있습니다. 내 솔루션은 여전히 이상적이지는 않지만 뭔가 있습니다.
#RSVP _onerror hack
#put this before creating application
oldMethod = Em.RSVP.Promise.prototype._onerror
Em.RSVP.Promise.prototype._onerror = (reason) ->
reason.label = this._label
oldMethod(reason)
App = Ember.Application.create(options)
그리고 약간 개선 된 코드는 방법
Ember.RSVP.configure('onerror', (error) ->
#handle situation when user in other tab logout from application.
if error.status == 401 #not authorized
window.location = '/login'
else
niceError = unless error.stack
message = {
label: error.label,
status: error.status,
statusText: error.statusText,
state: error.state(),
readyState: error.readyState,
responseText: error.responseText.replace(/<(?:.|\n)*?>/gm, '').substr(0,100)
}
new Error(Ember.inspect(message))
else
error
#here is method to send notification about error
MessageApp.errorHandler('RSVP', niceError)
당신의 아약스 호출처럼 중요시하는 점은 무엇과 어떻게 당신에게 성공/오류 후크를 해결의 OnError의 standart에 걸리지? –
@AlexLynham 직접 Ajax 호출을하지는 않지만 Ember Data가 모든 것을 처리합니다. –
내 생각 엔 RSVP가 ajax 약속을 어떻게 해결하는지와 그로부터 리턴 된 값을 어떻게 처리 할 수 있을지와 관련이있다. –