1

I'm using ES6 in my project and am finding that no console errors are being shown. I'm using Gulp with Babel (require('gulp-babel');) to transpile the ES6.

Take the following example: I instantiate a class which extends a parent, with method method1() then call a method that doesn't exist super.method2() in the child.

The program stops running but I get no errors. Why is this?

Other file:

...
API.Quest.getQuest(1).then((quest) => {
    this.quest = new Quest(quest);
    console.log('DONE'); // never gets here
}, (err) => {
    console.log('ERR', err);
});

Classes:

class Event {
    constructor(args, childEventClass, childEventClassName) {
        this.name = args.name;
        this.id = args.id;
        this.children = args[childEventClassName].map(eventObj => new childEventClass(eventObj));
        ...
    }

    method1() {
        console.log('Called parent method 1');
    }
}

class Quest extends Event {
    constructor(args) {
        super(args, Task, 'tasks');
        super.method2();
    }
};

class Task extends Event {
    ...
};

Gulp:

const babel = require('gulp-babel');
...
gulp.task('scripts', function() {
    return gulp.src([
        'js/**/*.js',
    ])
        .pipe(babel({
            presets: ['es2015']
        }))
        .pipe(concatJs('main.js'))
        .pipe(gulp.dest('build/js'));
});

Edit 2:

    API.Quest.getQuest(1).then((quest) => {
        // ... 
    }, (err) => {
        console.error('REJECT ERR', err);
        // Catch rejected promises
    }).catch((err) => {
        // Catch ?
        console.error('CATCH ERR', err);
    });
user3871
  • 12,432
  • 33
  • 128
  • 268
  • Where is `this.quest = new Quest(data);`? – Ry- May 17 '18 at 04:22
  • @Ry- see above plz – user3871 May 17 '18 at 04:23
  • 1
    `promise.then()` catches errors and converts them to rejected promises. You don’t appear to be doing anything with the rejected promise, so you won’t see it except as an unhandled rejection warning if your version of Node is new enough (6 or later, IIRC? If you’re using Node ≤4, definitely upgrade, as those versions aren’t supported anymore). – Ry- May 17 '18 at 04:51
  • @Ry- I'm console logging the error from the rejected promise. Moreover, that promise pertains to `get`'ing the Quest from the API, that's all. It won't error because it's successfully getting the Quest. – user3871 May 17 '18 at 04:58
  • The rejected promise is returned by `.then()`. You aren’t handling it. The operation is `promise.then(resolved, rejected)`; `resolved` throws here, `.then()` catches it, and it returns a rejected promise. The `rejected` function in the two-parameter `.then()` doesn’t handle rejections from the `resolved` function of the same `.then()`. Change `, (err) =>` to `).catch((err) =>` to see the difference. – Ry- May 17 '18 at 05:06
  • @Ry- I see! Thanks. Please see above "Edit 2". What's the difference then between the two error handlers? I guess the first `}, (err) => {` Rejected error is thrown if the API fails to get the item, and the second `}).catch((err) => {` is any application errors within Resolved? – user3871 May 17 '18 at 05:21
  • That’s correct! – Ry- May 17 '18 at 05:33
  • Yes. See the [difference between `.then(…, …)` and `.then(…).catch(…)`](https://stackoverflow.com/q/24662289/1048572). – Bergi May 17 '18 at 05:40

0 Answers0