From 99bf4aa4efe86711585a5b3782bd7d1a6bd264c6 Mon Sep 17 00:00:00 2001 From: Huan LI Date: Tue, 23 May 2017 18:02:59 +0800 Subject: [PATCH] clean(code): format --- src/puppet-web/bridge.ts | 19 +++++++++++-------- src/puppet-web/friend-request.ts | 2 +- src/puppet-web/puppet-web.ts | 2 +- src/puppet-web/wechaty-bro.js | 4 ++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/puppet-web/bridge.ts b/src/puppet-web/bridge.ts index 4295e65e..b799f1a5 100644 --- a/src/puppet-web/bridge.ts +++ b/src/puppet-web/bridge.ts @@ -222,20 +222,23 @@ export class Bridge { }) } - public verifyUserRequest(contactId, hello): Promise { + public async verifyUserRequest(contactId, hello): Promise { log.verbose('PuppetWebBridge', 'verifyUserRequest(%s, %s)', contactId, hello) if (!contactId) { throw new Error('no valid contactId') } - return this.proxyWechaty('verifyUserRequestAsync', contactId, hello) - .catch(e => { - log.error('PuppetWebBridge', 'verifyUserRequest(%s, %s) exception: %s', contactId, hello, e.message) - throw e - }) + try { + + return await this.proxyWechaty('verifyUserRequestAsync', contactId, hello) + + } catch (e) { + log.error('PuppetWebBridge', 'verifyUserRequest(%s, %s) exception: %s', contactId, hello, e.message) + throw e + } } - public verifyUserOk(contactId, ticket): Promise { + public async verifyUserOk(contactId, ticket): Promise { log.verbose('PuppetWebBridge', 'verifyUserOk(%s, %s)', contactId, ticket) if (!contactId || !ticket) { @@ -248,7 +251,7 @@ export class Bridge { }) } - public send(toUserName: string, content: string): Promise { + public async send(toUserName: string, content: string): Promise { if (!toUserName) { throw new Error('UserName not found') } diff --git a/src/puppet-web/friend-request.ts b/src/puppet-web/friend-request.ts index 41188781..2121596b 100644 --- a/src/puppet-web/friend-request.ts +++ b/src/puppet-web/friend-request.ts @@ -19,7 +19,7 @@ /* tslint:disable:no-var-requires */ const retryPromise = require('retry-promise').default -import Contact from '../contact' +import { Contact } from '../contact' import { Config, RecommendInfo, diff --git a/src/puppet-web/puppet-web.ts b/src/puppet-web/puppet-web.ts index 801bcee4..45bbd75f 100644 --- a/src/puppet-web/puppet-web.ts +++ b/src/puppet-web/puppet-web.ts @@ -652,7 +652,7 @@ export class PuppetWeb extends Puppet { */ public async friendRequestSend(contact: Contact, hello: string): Promise { if (!this.bridge) { - return Promise.reject(new Error('fail: no bridge(yet)!')) + throw new Error('fail: no bridge(yet)!') } if (!contact) { diff --git a/src/puppet-web/wechaty-bro.js b/src/puppet-web/wechaty-bro.js index c9684bc2..d4da751c 100644 --- a/src/puppet-web/wechaty-bro.js +++ b/src/puppet-web/wechaty-bro.js @@ -756,8 +756,8 @@ VerifyContent = VerifyContent || ''; - var contactFactory = WechatyBro.glue.contactFactory - var confFactory = WechatyBro.glue.confFactory + var contactFactory = WechatyBro.glue.contactFactory + var confFactory = WechatyBro.glue.confFactory var Ticket = '' // what's this? -- GitLab