Where to put generalized logic

benjamin.reuter
benjamin.reuter Posts: 3 🧑🏻‍🚀 - Cadet

Hi all,

are there any best practices for generalized logic?
Specifically, I am currently interested in creating custom exceptions that also accept context information in addition to the simple message andcode.

In the next step, I would like to extend the error handling to log that context information to improve our error handling.

In my current POC, I created a directory called "Common" in the PYZ namespace (or rather in our own namespace since we extended PYZ again) and inside it an "Exceptions" directory.

Is this way ok, or are there any suggestions for alternative approaches?

Comments

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,051 ⚖️ - Guardians (admin)

    Hello @benjamin.reuter ,

    normally we always find a module where a certain generalized logic could belong to.

    For example for the custom exception I could see it belonging to src/Pyz/(Service|Zed|Client|Shared|Glue)/ErrorHandler (there is one module without exception class in spryker core) .

    Or you could do your own util-module like src/Service/UtilError/ similar to the core util modules:

    Yet I also see a valid point in your solution. Since this would be used in several other modules it could make sense to make a new hierarchy for that like you did. Because with our module-separation you should ideally not just use it everywhere without injecting it through the dependency provider.

    Maybe the "kernel" module could be also suitable for you.

    Long story short: There is not the one most correct solution I can offer here.

    I still hope this brings you a bit forward. Very interesting question.

    All the best,

    Florian