Asked • 07/29/19

Best practice for angular service return value?

I have a number of angular services (e.g. a user service) which make various HTTP calls and I'm wondering what the best practice would be for handling errors. For example, I could do: function getAll(success, error) { $http.get('/api/users').then(success, error); } Or I could do: function getAll(success) { $http.get('/api/users').then(success, function(err) { success([]); }); }The advantage of the former is it is more configurable in case I wanted to do something special. However, the advantage of the second is that it keeps the controllers simpler and in the (hopefully rare) case that the server is down it won't simply throw an error but will just display blank/empty data.Is there any guideline or accepted best practice for this kind of situation?

1 Expert Answer


Stefan R. answered • 02/28/20

5.0 (625)

Senior Web Developer with the urge to spread knowledge

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.


Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.