I’m currently working on an ember app using ember-data for the communication with the back-end (Rails-API). At the moment my API returns HTTP status code 403 (forbidden), if a user tries to access a resource without permission. For some days I searched the web, how HTTP errors could be handled globally on my ember app. I only found how to handle these kind of errors on route changes (
afterModel), but I didn’t find anything usable for
save, so I started to look at the ember-data code, that is responsible for validation and http errors. The only way I could find at the moment, is to catch the error on
save, and do some custom error handling for every models
save, like this:
actions: saveModel: (model) -> model.save().catch((reason) -> # error handling, show error message, route transition, ...
But for my usecase and I think also for usecases of others, it would be nicer to have the errors bubble up like they do on route changes, such that you can use:
actions: errors: (error) -> # error handling or bubble up to parent route and so on.
With such a solution it would be very easy to have specific error handling or a global error handle for authorization and other global stuff.
So I ask myself, how do others implement the server side error handling in there ember apps?