Promise process control problem

  node.js, question

Node.js has only been studying for a few months, and only part of the experience is different. I still hope to read critically. .

Promise I use for asynchronous control.

It can be roughly divided into situations.

Execution Process of Upper and Lower Serial Dependencies
Promise.reslove(xxx)

.then()
 .then()
 .then()
 .catch();

This kind of operation is very simple. Each step depends on the result of the previous step. The result jumps out abnormally and finally returns.

Parallel and Independent Operation Execution Process
Promise.all([xxx,xxxx,xxx])

.then()
 .then()
 .then()
 .catch();

Note: Dependency-free here means that all methods in the ALL parameter array are not dependent on each other.

All asynchronous operations are stored in the array parameters of the all method.

This logic is very simple and clear.
But the actual situation is often not, such as:
We sometimes appear
Promise.reslove(xx)
.then(function(result){

if(result){
 //jump out of this promise and return directly.
 //How to deal with this
 ... this way of writing cannot be done here, and the result return cannot be error.
 }else{
 return xxx;  //Continue to execute downwards.  .
 bracket

})
.then()
.then()
.catch();
I long for a good solution to promise under this logic. . . . . .
This is a solution for friends, but it feels weird. . . . . . .
return new Promise(function (resolve, reject) {

Promise.resolve(xxx).then((user) => {
 if (user) {
 resolve({isNew: false, user: user});
 } else {
 Varnewuser = {deviceid: deviceid, name:' anonymous'};
 add(newUser).then((returnUser) => {
 resolve({isNew: true, user: returnUser});
 }).catch((err) => {
 reject(err);
 });
 bracket
 }).catch((err) => {
 reject(err);
 });

thenThere are two parameters, one is a successful callback and the other is an error callback. If you handle the error in the error callback, you will not enter the last one.catchFor example:

Promise.resolve(xxx)
 .then(function(result) {
 if (result) {
 throw new Error("My bad");
 } else {
 
 bracket
 , function(err) {
 
 }).then()
 .then()
 .catch();