A
A
Abra Kadabra2018-06-22 21:02:19
JavaScript
Abra Kadabra, 2018-06-22 21:02:19

Is it logical to use a service within a service?

There is a service that retrieves data from the server, and if a session error is returned, you need to transfer the user to the login.
Would it be logical to add a service that will use the router and redirect to the login page when an error occurs. (This is certainly more logical than declaring your own redirect in each service)
But perhaps there is another option for this? Signing up for a global event?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny, 2018-06-22
@Jmaster

If you know for sure that with a certain server response, you always have to throw the user to login, then I would google something like "http global error handler" and put the redirect inside. Regarding the service in the service: in OOP this should be avoided if the services are, roughly speaking, on the same application layer, because this leads to complication of support, readability, and also circular dependency may appear in the future . But Typescript, of course, cannot be called a full-fledged OOP language, so everyone decides for himself :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question