-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store service filters erros provided in exception #8188
Comments
The original Error is still thrown and should still contain the
we don't filter anything out. In fact just the opposite! If the serializer had implemented the (semi-secret) method called serializer.extractErrors, we pass them to it unmodified. We then transform the result back into JSON:API errors array format. This transformation is roughly unchanged for ~3-4 years, here it is in 4.4 and 3.16 If the serializer does not implement serializer.extractErrors (it is preferred and better that it does not) then we pass the errors entirely unmodified to the cache We store these errors still unmodified When I suspect the issue you have here is that we leaked the original We could potentially restore this, though it would in many ways be a bug. I suspect the real solution here is for you to simply delete the serializer's |
closing for now, happy to reopen for further discussion if it sounds merrited. |
@runspired yes please I've just attempted to upgrade my application from ED 4.6.4 to 4.7.3 and observed the same behaviour - exactly when the PR was released. I think there's a regression with error handling here.
Correct - except the data/packages/store/addon/-private/store-service.ts Lines 2695 to 2697 in 3bc74cb
After the code changes, After 4.7.3 there's no way to actually return the error as the server gave it. For example, my error is like this; {
errors: [{title: 'Unprocessable Entity', status: 422, detail: 'subscription no more student licences'}],
isAdapterError: true
message: "The adapter rejected the commit because it was invalid"
name: "Error",
stack: "......"
} My application expects to be able to use the errors array as is. } catch (e) {
if (e.errors[0].status === 422) doThing()
}
Each time you've claimed the error is passed/stored unmodified, it's actually had its
That sounds about right. But ... what am I supposed to do?
I've tried implementing a passthrough for the serializer.extractErrors() function (as I mentioned above), but because the errors are still run through I think I would have been more prepared for this had there been a mention in the changelog or breaking changes or something. This was really painful to debug |
Actually, I believe that error I gave and most of the errors I am having issues with do infact adhere to the JSONAPI spec. Both the But the spec says that it can be omitted https://jsonapi.org/format/#errors
Regardless, I then tried adding in the error/source/pointer/data as below, to indicate that the error isn't meant for any attributes. Unforunately, the errors array is still not passed through unmodified
|
It's looking like my only option here will be to implement extractErrors() to store the server error on a new property, and then refactor the error handling throughout my application to instead point to that. But if you've got any better suggestions, I'll take anything over that option |
I think you want no extractErrors hook at all ... |
would be happy to pair btw, there's a couple of nuances here and could be a weird interplay of things. |
I didn't even think of that.. Would that be considered a public API thing to do? Is that likely to have other ramifications? (do other parts of ember-data rely on these errors having been extracted & formatted?)
I appreciate that offer - I may take you up on it if I have trouble but I do think I have grokked the relevant aspects of this |
Ok - I've thought a bit more about this.
While that's true, that code that processes errors hadn't changed in a long time, what is also true is that nobody was forced to use it for a long time.. I think a big part of the reason I'm having difficulty with the changes isn't necessarily that the errors are being parsed correctly now without an escape hatch - it's because the data/packages/legacy-compat/src/legacy-network-handler/legacy-network-handler.ts Lines 277 to 283 in bf5b0d0
That functions' return type is data/ember-data-types/q/record-data-json-api.ts Lines 25 to 41 in bf5b0d0
I suspect it would be resolved to the point where most of my error handling won't even need to change, and likely the same for other applications. This would also solve the OP's need for the missing the I'm going to put a PR together with what I think needs to change, to help explain. |
I've put this PR together |
The PR I mentioned is a proof of concept if we wanted to patch the legacy code to still work the same as it used to, but I've instead now opted to set Hopefully someone out there finds that useful |
@runspired We are using JSON (not json api) serializer (which already implements {
errors: [{
code: '^error_message^',
meta: { token_args: ['arg1', 'arg2'] },
status: '422',
}],
} So the problem is that in the catch clause of |
@azhiv sounds like in your case you weren't using EmberData's record.errors behavior before at all. Simply removing extractErrors should work in that case I think. |
@runspired Thank you, this seems to fix the problem. |
Merge of #8084 introduced some breaking changes to error handling.
Before this commit, when InvalidError was created with array of errors object, it was possible to inspect this array in application, but now it is filtered out - I assume that in the following code (code fragment from store-service.ts)
As a result
code
property is filtered out (and other properties mentioned in https://jsonapi.org/format/#errors).JSON:API specification states that
My application relayed on error codes, but now they are not available, and requires major refactoring to update to new version of Ember Data.
I'm not sure if overriding title to a fixed English value is a good idea (for example if title was localized on server side - it can also break some apps).
The text was updated successfully, but these errors were encountered: