Save operation does not set errors
I would appreciate it if you could look into this:
I try to save a model using model.save:
model.save().then((result) => {
console.log('Save operation finished')
console.log('Result: ')
console.log(result)
console.log('Model:')
console.log(model)
console.log('Error in model:')
console.log(model.error)
})
The server returns a 422 (Unprocessable Entity) error. I see the following:
- The
resultcontains the JSON error from the server. - The model has previously edited values set.
- The
model.erroris null
The last point is obviously a problem. Would you consider this a bug? If this is intended, how is it possible to spot the error?
I don't know how to reproduce this. A 422 should halt the save operation and set the payload of the server response as errors. Could you write a failing test for that scenario? Thanks in advance!
I ran into this as well. The problem is that the adapters expect that the server returns the errors in the errors key.
https://github.com/masylum/mobx-rest-fetch-adapter/blob/master/src/index.js#L52 https://github.com/masylum/mobx-rest-jquery-adapter/blob/master/src/index.js#L92
I think the adapters shouldn't assume anything regarding to the backend response, or al least we should have some way to customize how to extract the error from the response.
Edit: Actually it wasn't the same scenario. In my case the promise got rejected but I couldn't get the error payload.
I think this was the cause https://github.com/masylum/mobx-rest-fetch-adapter/pull/2. @ax487, were you using the fetch adapter?
I think that was the case. We could consider though to remove the assumption that the response always includes an errors key, or at least make it configurable (for backward compatibility).