loading
open in
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Promise.resolve({ foo: 5 })
	.then(obj => {
		console.log('then 1');

		if (obj.foo == 1) {
			return 'youpi';
		}

		if (obj.foo == 2) {
			return 'oulala';
		}

		if (obj.foo == 3) {
			throw new Error('ErrorInstance');
		}

		if (obj.foo == 4) {
			throw 'ERROR';
		}

    if (obj.foo == 5) {
			throw 'COMPLEXE_ERROR';
		}
	})
	.catch(error => {
		console.log('catch 1');
		console.log('error', typeof error, error.message, error);

		if (error.message === 'ErrorInstance') {
			return 'WeirdOne';
		}

    if (error === 'COMPLEXE_ERROR') {
			throw {
        name  : 'COMPLEXE_ERROR',
        value : 'WeirdOne'
      };
		}

		throw error;
	})
	.then(fromOne => {
		console.log('then 2');
		console.log('param', fromOne);

		if (fromOne === 'oulala') {
			throw new Error('ErrorInstance');
		}

		return fromOne;
	})
	.then(fromTwo => {
		console.log('then 3');
		console.log('param', fromTwo);
	})
	.catch(error => {
		console.log('catch 2');
		console.log('error', typeof error, error);
	});
node v9.7.1 linux/amd64