Skip to content

Commit 7c15ec9

Browse files
committed
always reject with objects
1 parent b014ce2 commit 7c15ec9

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/cloud/social/provider.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,15 @@ export class CloudSocialProvider {
367367
public inviteUser = (clientId: string): Promise<Object> => {
368368
log.debug('inviteUser');
369369
if (!(clientId in this.savedContacts_)) {
370-
return Promise.reject(new Error('unknown cloud instance ' + clientId));
370+
return Promise.reject({
371+
message: 'unknown cloud instance ' + clientId
372+
});
371373
}
372374
if (this.savedContacts_[clientId].invite.user !== ADMIN_USERNAME) {
373-
return Promise.reject(new Error('user is logged in as non-admin user ' +
374-
this.savedContacts_[clientId].invite.user));
375+
return Promise.reject({
376+
message: 'user is logged in as non-admin user ' +
377+
this.savedContacts_[clientId].invite.user
378+
});
375379
}
376380
return this.reconnect_(this.savedContacts_[clientId].invite).then(
377381
(connection: Connection) => {
@@ -436,7 +440,9 @@ class Connection {
436440
// TODO: timeout
437441
public connect = (): Promise<void> => {
438442
if (this.state_ !== ConnectionState.NEW) {
439-
return Promise.reject(new Error('can only connect in NEW state'));
443+
return Promise.reject({
444+
message: 'can only connect in NEW state'
445+
});
440446
}
441447
this.state_ = ConnectionState.CONNECTING;
442448

@@ -465,7 +471,9 @@ class Connection {
465471
ZORK_HOST, ZORK_PORT, (e: Error, stream: ssh2.Channel) => {
466472
if (e) {
467473
this.close();
468-
R(new Error('error establishing tunnel: ' + e.toString()));
474+
R({
475+
message: 'error establishing tunnel: ' + e.message
476+
});
469477
return;
470478
}
471479
this.setState_(ConnectionState.WAITING_FOR_PING);
@@ -482,8 +490,9 @@ class Connection {
482490
F();
483491
} else {
484492
this.close();
485-
R(new Error('did not receive ping from server on login: ' +
486-
reply));
493+
R({
494+
message: 'did not receive ping from server on login: ' + reply
495+
});
487496
}
488497
break;
489498
case ConnectionState.ESTABLISHED:
@@ -510,7 +519,9 @@ class Connection {
510519
// TODO: does this occur outside of startup, i.e. should it always reject?
511520
log.warn('%1: tunnel error: %2', this.name_, e);
512521
this.close();
513-
R(new Error('could not establish tunnel: ' + e.toString()));
522+
R({
523+
message: 'could not establish tunnel: ' + e.message
524+
});
514525
}).on('end', () => {
515526
// Occurs when the stream is "over" for any reason, including
516527
// failed connection.
@@ -531,7 +542,9 @@ class Connection {
531542
// TODO: does this occur outside of startup, i.e. should it always reject?
532543
log.warn('%1: connection error: %2', this.name_, e);
533544
this.close();
534-
R(new Error('could not login: ' + e.toString()));
545+
R({
546+
message: 'could not login: ' + e.message
547+
});
535548
}).on('end', () => {
536549
// Occurs when the connection is "over" for any reason, including
537550
// failed connection.

0 commit comments

Comments
 (0)