Generic Error Handling


#1

Hey there I am trying to figure out if there are any best practices for handling errors in a generic way, not for the purpose of sending to our bug tracking system (wee already have that in place), but for alerting the user that something went wrong. I’m not sure if the onerror handler on the Ember object is the right way of handling this or where the best entry point is.


#2

You can define an error action on any route as far as I know but for generic handling you could just put something like this in your application route, you would probably want to check error.status for at least the most common cases.

I’m still pretty new to Ember so there might be a better way to do this!

actions: {
	error: function(error, transition) {
		// Do something to let the user know there was a problem
		return false;
	}
}

#3

Part of it depends on where the error is happening.

For the specific case of model hooks returning a promise that eventually gets rejected, you should be able to define a top level error template and be good to go. It may be a good idea to override the application route’s error action so you can try to gather some useful information for either yourself or the user.

For errors happening anywhere else, it really depends on where the error happens.


#4

We were able to get the error action in routes working, but we would like something that acts as a catch-all for errors that essentially happen anywhere. The tricky piece I have found in handling this is there are some errors that raise that do not actually affect the customer (for example our pusher library failing to connect), and preferably we would not show an error for those. This is obviously pretty specific and tricky, but it seems like we are already on the right path. I just didnt want to reinvent the wheel if someone on here had already solved this problem.