ember-data からの 403 エラーを処理する最良の方法は何ですか?
検証以外のエラーを処理する最善の方法を知りたいです。たとえば、ユーザーがアクションの実行を許可されていない場合に http 403 を返す可能性のあるコードが少しあります。たとえば、次のコードがあります。
contact.set 'something', 'something'
transaction = @get('store').transaction()
transaction.add(contact)
contact.one 'becameInvalid', (result) =>
#display some error message
contact.one 'becameError', (result) =>
# code does not get here for some reason
transaction.rollback()
#display some error message
transaction.commit()
403 エラーが発生した場合、上記のbecameError
ハンドラーは呼び出されず、オブジェクトのステート マシンはそのrootState.error
状態のままになり、オブジェクトにプロパティを設定しようとする後続の試みは、今や悪名高く恐ろしいもののために失敗します。
uncaught Error: Attempted to handle event `willSetProperty` on <Radium.Contact:ember2286:17> while in state rootState.error. Called with {reference: [object Object], store: <Radium.Store:ember3219>, name: name}
私の考えは、didError
メソッドをオーバーライドできるということです:
didError: function(store, type, record, xhr) {
if (xhr.status === 422) {
var json = JSON.parse(xhr.responseText),
serializer = get(this, 'serializer'),
errors = serializer.extractValidationErrors(type, json);
store.recordWasInvalid(record, errors);
} else {
this._super.apply(this, arguments);
}
},
私の質問は、ステート マシンが に移行した後、オブジェクトを使用可能な状態に戻すにはどうすればよいかということですrootState.error
。