提交 ba8bcc17 编写于 作者: Y Yuan Gao 提交者: Huan (李卓桓)

better error message for contact self operations (#1550)

上级 e410eb27
...@@ -106,8 +106,13 @@ export class ContactSelf extends Contact { ...@@ -106,8 +106,13 @@ export class ContactSelf extends Contact {
*/ */
public async qrcode (): Promise<string> { public async qrcode (): Promise<string> {
log.verbose('Contact', 'qrcode()') log.verbose('Contact', 'qrcode()')
let puppetId: string
if (this.id !== this.puppet.selfId()) { try {
puppetId = this.puppet.selfId()
} catch (e) {
throw Error('Can not get qrcode, user might be either not logged in or already logged out')
}
if (this.id !== puppetId) {
throw new Error('only can get qrcode for the login userself') throw new Error('only can get qrcode for the login userself')
} }
...@@ -141,7 +146,14 @@ export class ContactSelf extends Contact { ...@@ -141,7 +146,14 @@ export class ContactSelf extends Contact {
return super.name() return super.name()
} }
if (this.id !== this.puppet.selfId()) { let puppetId: string
try {
puppetId = this.puppet.selfId()
} catch (e) {
throw Error('Can not set name for user self, user might be either not logged in or already logged out')
}
if (this.id !== puppetId) {
throw new Error('only can set name for user self') throw new Error('only can set name for user self')
} }
...@@ -166,7 +178,14 @@ export class ContactSelf extends Contact { ...@@ -166,7 +178,14 @@ export class ContactSelf extends Contact {
public async signature (signature: string): Promise<void> { public async signature (signature: string): Promise<void> {
log.verbose('ContactSelf', 'signature()') log.verbose('ContactSelf', 'signature()')
if (this.id !== this.puppet.selfId()) { let puppetId: string
try {
puppetId = this.puppet.selfId()
} catch (e) {
throw Error('Can not set signature for user self, user might be either not logged in or already logged out')
}
if (this.id !== puppetId) {
throw new Error('only can change signature for user self') throw new Error('only can change signature for user self')
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册