Reputation: 2351
I am attempting a post action using Ember-Data, and getting the following error which seems pretty common:
Error: The adapter rejected the commit because it was invalid
Problem is, seems like usually this returns more specific errors; I am only seeing the above message and a generic 422 error from the browser.
Does anyone know what I can do to access any specific error messages that might be thrown?
Potentially relevant info:
Using jsonapify on an express server to write to MongoDB
router.post('/',
jsonapify.create('info'),
logger.logErrors(), jsonapify.errorHandler()
);
I would expect the following code to log some sort of response but I am never able to see the message in this console.log:
info.save().then((response)=> {
console.log(`Server responded with ${response}`);
});
Sorry for the vagueness here, I'm sure there could be all sorts of problems with my models and whatnot, but I want to know what I can do to find the more specific errors if they exist.
Thanks much and plz lmk if I can update with more info.
Upvotes: 0
Views: 396
Reputation: 2661
.then()
takes two arguments, like so: .then(success, failure)
the first one being a function to be called on success, and the second to be called on failure. A 422 response is a failure, and your current code only has a success handler, so it will never be called. Basically, copy-paste your current success handler to be the second argument to your .then()
call.
Also, generally in your browser you can open up the inspector and take a look at the request in the 'network' tab.
Your new debugging code could look something like this:
let success = (response) => {
console.log(`Server responded with ${response}`);
};
let failure = (response) => {
debugger;
};
info.save().then(success, failure);
Then you should be able to poke around the response object in your js console and see what's going wrong.
Upvotes: 0