Giter Site home page Giter Site logo

Comments (4)

gnugat avatar gnugat commented on August 22, 2024

Hey @funivan, that's a good question! To answer it I'll just remind you that using strict types would raise a Fatal Error (Uncaught TypeError: Argument <argument number> passed to <function> must be of the type <expected type>, <received type> given).

I'm fine having these kind of fatal errors being raised when passing an invalid argument to a service (as you can see later in the series, like in Event constructor or in AnEventHappened), but when it comes to the entry point of our domain (the Command objects like LandRover) I'd rather have an InvalidArgumentException.

I hope that makes sense for you.

from gnugat.github.io.

funivan avatar funivan commented on August 22, 2024

I understand your position. But what benefits you get when you use InvalidArgumentException instead of type error?

from gnugat.github.io.

gnugat avatar gnugat commented on August 22, 2024

Its mainly for error classification: let's say your logic is used in a HTTP application, an API. Then you only need to catch all InvalidArgumentException and return a 422 UNPROCESSABLE ENTITY response.

To be fair, instead of throwing \InvalidArgumentException it might be better to throw a custom MarsRover\Exception\ValidationFailedException.

from gnugat.github.io.

funivan avatar funivan commented on August 22, 2024

Thanks. Error classification is good option to choose;)

from gnugat.github.io.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.