Reputation: 2066
Using Ember and Ember-data, I work against an API that I don't control.
In a very specific case, it returns an apparently valid response (status 200), that turns out to be not that useful after inspecting it. However, this response is complex, and it's not until the serializer that I can realize this.
Therefore, the question: is there a way to return an error to the client (something similar to what a 404 response would do) from the serializer?
If the above is not possible, I have alternative ideas:
Any other alternative ideas? Thank you in advance.
Upvotes: 1
Views: 146
Reputation: 368
To reject an invalid or useless object at the serializer level, you would need to throw an exception or return undefined
from the normalizeResponse
method.
If you're loading resources as part of a model hook, this will cause the promise to reject, and you'll be able to handle the error as if it was a 404 from the API.
Upvotes: 1