我试图在Ember-CLI-Mirage中返回不同的响应,具体取决于记录是否在(假)数据库中。但是,即使我返回404响应代码,当我返回没有有效JSONAPI响应的响应时,我仍然会收到适配器错误。
this.get('/users/:id', (db, request) => {
let user = db.users.find(request.params.id);
if (user) {
return jsonapi.serializeOne(user); // works
} else {
return new Mirage.Response(404, null, null);
}
});
这是路线:
import Ember from 'ember';
export default Ember.Route.extend({
errorRedirectTo: 'users',
model: function(){
return this.store.createRecord('user');
}
});
错误讯息:
Error while processing route: user Adapter operation failed Error: Adapter operation failed
at new Error (native)
at Error.EmberError (http://localhost:4200/assets/vendor.js:26266:21)
at Error.ember$data$lib$adapters$errors$$AdapterError (http://localhost:4200/assets/vendor.js:126403:50)
at ember$data$lib$system$adapter$$default.extend.handleResponse (http://localhost:4200/assets/vendor.js:128081:16)
at ember$data$lib$system$adapter$$default.extend.ajax.Ember.RSVP.Promise.hash.error (http://localhost:4200/assets/vendor.js:128177:33)
at jQuery.Callbacks.fire (http://localhost:4200/assets/vendor.js:3350:30)
at Object.jQuery.Callbacks.self.fireWith [as rejectWith] (http://localhost:4200/assets/vendor.js:3462:7)
at done (http://localhost:4200/assets/vendor.js:9518:14)
at Object.jQuery.ajaxTransport.send.callback (http://localhost:4200/assets/vendor.js:9920:8)
at Object._readyStateChange (http://localhost:4200/assets/vendor.js:69915:14)