I am working on an API using Laravel. I am writing business logic and application logic and trying my best to separate them as much as possible. However, I am new in such concepts. For example, I have the logic to log the user in. I have to check:
- If the given creds valid or not?
- If the creds exist in the system?
- If user is active or not
- save the data
- Try to get some data, but not found
- and so on...
I am not checking all this in the controller(as I think it's not the controller's responsibility), but in a separate LoginFormProcessor
Class which is delegated by the Controller. If all the checks passes, the LoginFormProcessor
will delegate the Object to save/get the object in/from the database. Here is the hierarchy:
Controller -> LoginFormProcessor -> Repository
I want to return the detailed JSON errors (if any) occurred in the LoginFormProcessor
or Repository
but not directly from these classes (as this is not their responsibility) but from the Controller.
How I can return the mentioned errors to Controller so the Controller could create a meaningful response and sent to the client. Should I return some integer type errorCodes from the LoginFormProcessor
and Repository
? But then I'll have to check for all the possible error codes, an other headache. I don't think it's a good practice.
Any suggestion and good practices about it?
Aucun commentaire:
Enregistrer un commentaire