Code Monkey home page Code Monkey logo

Comments (5)

adrai avatar adrai commented on May 26, 2024

The type (prototype) of the events are note exposed. Why do you need it? Can't you simple check err.name
or
subscribe to domain.onEvent(function (evt) {}); ?

from node-cqrs-domain.

nizachon avatar nizachon commented on May 26, 2024

Type of the events or type of the errors? It's the latter (the error types) I was talking about.

In my case, I had to implement custom command handler to perform cross-aggregate validation (check that the aggregate referenced by parentId property of the command already exists.) If that validation failed, I would call the callback with ValidationError and that would eventually cause domain.createCommandRejectedEvent() to create a CommandRejected event. The problem is that neither ValidationError nor any other pre-defined error type that createCommandRejectedEvent method checks against are exposed (?). Any other error type causes createCommandRejectedEvent to do nothing.

https://github.com/adrai/node-cqrs-domain/blob/master/lib/domain.js#L173

The code:

module.exports = require('cqrs-domain').defineCommandHandler({
}, function (aggregateId, command, commandHandler, callback) {
    // if 'command.parentEntryId' is provided, check that the parent entity exists
    // everything else - just follow DefaultCommandHandler

    var self = this;

    var parentId = !!this.definitions.command.payload && !!command.payload.parentEntityId
        ? command.payload.parentEntityId
        : null;  // use 'dotty'

    async.waterfall([
            function (clb) {
                if (!!parentId) {
                    self.loadAggregate(command.payload.parentEntityId, clb);
                } else {
                    clb(null, null, null, false);
                }
            },
            function (aggregate, stream, isNewSnapShotNeeded, clb) {
                if (!!parentId && (!aggregate || aggregate.getRevision() === 0)) {
                    clb(// new ValidationError('Parent Entity with id: ' + parentId + ' does not exist')

                         { name: 'ValidationError', message: 'Parent Entity with id: ' + parentId + ' does not exist' }
                    );
                } else {
                    clb(null);
                }
            }
        ],
        function (err) {
            if (!!err) {
                callback(err);
            } else {
                self.workflow(aggregateId, command, callback);
            }
        }
    )
});

from node-cqrs-domain.

adrai avatar adrai commented on May 26, 2024

Ok I see what you mean... I will expose these errors for the next release, ok?

from node-cqrs-domain.

nizachon avatar nizachon commented on May 26, 2024

Thank you!

from node-cqrs-domain.

adrai avatar adrai commented on May 26, 2024

v1.4.1

from node-cqrs-domain.

Related Issues (20)

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.