Proper way of handling Errors

Hi, i am a little confused about proper way to handle errors, especially or http calls or database calls. Are there any best practises for this? For example, when i call http post from service, how should be errors handled? With map catch methods right in http post, or after that in most classical way with err block in subscribe method?

Another thing id like to ask is where should be some output for user generated, when error occured. For example if i want to display error message in Toast, should i do it right in the service method with http call, or is it better later in Page?

Thx for errors in advance :slight_smile: It would really help me to clarify this :slight_smile:

You will likely find as many opinions on this as there are users on this forum, but the way I handle it is to have my service providers either return the data that was requested (in the case of a successful call) or to return an error (obviously in the case of an unsuccessful call!).

Then in my pages I either consume the data, or display the error (normally in a toast). I don’t like having my providers be in charge of view stuff as they shouldn’t care who’s using them, separation of responsibility 'n wot.

1 Like