Skip to content

Commit de61813

Browse files
committed
all rejections should be with weird freedomjs error type
1 parent 486ca2f commit de61813

1 file changed

Lines changed: 34 additions & 15 deletions

File tree

src/cloud/social/provider.ts

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,9 @@ export class CloudSocialProvider {
289289
log.debug('saved contacts');
290290
}).catch((e) => {
291291
log.error('could not save contacts: %1', e);
292-
Promise.reject(e);
292+
Promise.reject({
293+
message: e.message
294+
});
293295
});
294296
}
295297

@@ -322,7 +324,9 @@ export class CloudSocialProvider {
322324
// the instance (safe because all we've done is run ping).
323325
log.info('new proxying session %1', payload.proxyingId);
324326
if (!(destinationClientId in this.savedContacts_)) {
325-
return Promise.reject(new Error('unknown client ' + destinationClientId));
327+
return Promise.reject({
328+
message: 'unknown client ' + destinationClientId
329+
});
326330
}
327331
return this.reconnect_(this.savedContacts_[destinationClientId].invite).then(
328332
(connection: Connection) => {
@@ -335,30 +339,39 @@ export class CloudSocialProvider {
335339
connection.sendMessage(JSON.stringify(payload));
336340
});
337341
} else {
338-
return Promise.reject(new Error('unknown client ' + destinationClientId));
342+
return Promise.reject({
343+
message: 'unknown client ' + destinationClientId
344+
});
339345
}
340346
}
341347
} else {
342-
return Promise.reject(new Error('message has no or wrong type field'));
348+
return Promise.reject({
349+
message: 'message has no or wrong type field'
350+
});
343351
}
344352
} catch (e) {
345-
return Promise.reject(new Error('could not de-serialise message: ' + e.message));
353+
return Promise.reject({
354+
message: 'could not de-serialise message: ' + e.message
355+
});
346356
}
347357
}
348358

349359
public clearCachedCredentials = (): Promise<void> => {
350-
return Promise.reject(
351-
new Error('clearCachedCredentials unimplemented'));
360+
return Promise.reject({
361+
message: 'clearCachedCredentials unimplemented'
362+
});
352363
}
353364

354365
public getUsers = (): Promise<freedom.Social.Users> => {
355-
return Promise.reject(
356-
new Error('getUsers unimplemented'));
366+
return Promise.reject({
367+
message: 'getUsers unimplemented'
368+
});
357369
}
358370

359371
public getClients = (): Promise<freedom.Social.Clients> => {
360-
return Promise.reject(
361-
new Error('getClients unimplemented'));
372+
return Promise.reject({
373+
message: 'getClients unimplemented'
374+
});
362375
}
363376

364377
public logout = (): Promise<void> => {
@@ -398,17 +411,21 @@ export class CloudSocialProvider {
398411
log.debug('acceptUserInvitation');
399412
try {
400413
var invite = <Invite>JSON.parse(inviteJson);
414+
log.debug('decoded invite: %1', invite);
401415
return this.reconnect_(invite).then((connection: Connection) => {
402416
// Return nothing for type checking purposes.
403417
});
404418
} catch (e) {
405-
return Promise.reject(new Error('could not parse invite code: ' + e.message));
419+
return Promise.reject({
420+
message: 'could not parse invite code: ' + e.message
421+
});
406422
}
407423
}
408424

409425
public blockUser = (userId: string): Promise<void> => {
410-
return Promise.reject(
411-
new Error('blockUser unimplemented'));
426+
return Promise.reject({
427+
message: 'blockUser unimplemented'
428+
});
412429
}
413430

414431
// Removes a cloud contact from storage
@@ -599,7 +616,9 @@ class Connection {
599616
private exec_ = (command: string): Promise<string> => {
600617
log.debug('%1: execute command: %2', this.name_, command);
601618
if (this.state_ !== ConnectionState.ESTABLISHED) {
602-
return Promise.reject(new Error('can only execute commands in ESTABLISHED state'));
619+
return Promise.reject({
620+
message: 'can only execute commands in ESTABLISHED state'
621+
});
603622
}
604623
return new Promise<string>((F, R) => {
605624
this.connection_.exec(command, (e: Error, stream: ssh2.Channel) => {

0 commit comments

Comments
 (0)