Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should throw Exception when there have API Error. #683

Closed
amyhuangxbd opened this issue Jul 24, 2017 · 9 comments
Closed

Should throw Exception when there have API Error. #683

amyhuangxbd opened this issue Jul 24, 2017 · 9 comments

Comments

@amyhuangxbd
Copy link

amyhuangxbd commented Jul 24, 2017

I try to modify contact remark in contact-bot.ts
The main code is:

for (let i = 0; i < contactList.length; i++) {
      const contact = contactList[i]
      if (contact.personal()) {
          log.info('Bot', `personal ${i}: ${contact.get('name')} : ${contact.id}`)
          const remarkUser = '测试' + contact.get('name')
          const ret = await contact.alias(remarkUser)
          if (ret) {
            console.log('ok')
          } else {
            console.error('failed')
          }
          await contact.refresh()
          log.info('Bot', 'get alias: %s', contact.alias())

      }
    }

Expected behavior

Remark should be modified,
And I got the log that tells me the remark is modified, however, in fact, the remark isn't modified.

Below is part of logs:

ok
07:23:31 INFO Bot get alias: INFO Bot get alias: %s 测试转世一瞬
07:23:31 INFO Bot personal 188: 花月正春风 : @4223c4c6f8f25f186f6501dc353e88d0ce5971e7faeef50e77933a44002d8da0 INFO Bot personal 188: 花月正春风 : @4223c4c6f8f25f186f6501dc353e88d0ce5971e7faeef50e77933a44002d8da0
ok
07:23:31 INFO Bot get alias: INFO Bot get alias: %s 测试花月正春风
07:23:31 INFO Bot personal 190: 会飞的灰灰^o^ : @a32609b330af4c163c67859147f833d5 INFO Bot personal 190: 会飞的灰灰^o^ : @a32609b330af4c163c67859147f833d5
ok
07:23:32 INFO Bot get alias: INFO Bot get alias: %s 测试会飞的灰灰^o^
07:23:32 INFO Bot personal 195: Chandelier : @0ae7ef3b90b50aae9338cf65e61b1879fe959035da8e348664ced6201d3cf977 INFO Bot personal 195: Chandelier : @0ae7ef3b90b50aae9338cf65e61b1879fe959035da8e348664ced6201d3cf977
ok
07:23:32 INFO Bot get alias: INFO Bot get alias: %s 测试Chandelier
07:23:32 INFO Bot personal 201: Jarrah - 100offer : @348213df31a64f2f2c9ab614851d2c759605f8868a1927f727799514e7c6a58a INFO Bot personal 201: Jarrah - 100offer : @348213df31a64f2f2c9ab614851d2c759605f8868a1927f727799514e7c6a58a

Actual behavior

@amyhuangxbd
Copy link
Author

It seems that contact.alias(string) doesn't work anymore,
I have tried contact.alias(string) in ding-dong-bot.ts, and it also doesn't work .
if(m.self()||room){ return; } else{ const remarkUser = '重复用户 - ' + contact.get('name') const ret = await contact.alias(remarkUser) if (ret) { console.log('ok') } else { console.error('failed') } await contact.refresh() log.info('Bot', 'get alias: %s', contact.alias()) }

@lijiarui
Copy link
Member

You should wait for a while.
Becasue it change alias on web wechat, and it needs some time to synchronize to mobile wechat.

@lijiarui
Copy link
Member

Btw, please change ` to ``` for your log info as I modified for your first comment.

@huan
Copy link
Member

huan commented Jul 24, 2017

It's related to #596 #412

After those issues, I start to think that we should throw an Exception if the operation failed, instead of return a false silently.

Because it might be an Error in our design pattern: Should throw Exception if Server fail.

The related method should include(but not limited):

  1. alias
  2. say
  3. accept
  4. add
  5. del
  6. etc...

@huan huan added the bug label Jul 24, 2017
@huan huan changed the title Cannot remark contact successfully when I get the contactList Should throw Exception when there have API Error. Jul 24, 2017
@amyhuangxbd
Copy link
Author

@lijiarui Thanks for your reply and support!
In fact, I have tried many times to change the remark. And only a few times was successful,
In most cases, it is failing. contact.alias(String) seems unstable.

@iyjian
Copy link
Contributor

iyjian commented Aug 7, 2017

@amyhuangxbd YES it is unstable, do u have any workaround?

@amyhuangxbd
Copy link
Author

I can remark friend's alias in web version successfully, but the alias unable to synchronize to the phone.
I haven't found the reason why the web and the phone can't sync.

@huan
Copy link
Member

huan commented Aug 22, 2017

@amyhuangxbd You did not remark friend's alias in web version successfully, it's only changed inside your browser, the server did never accept that.

If you refresh the browser or re-login, you will find out that the new "alias/remark" is lost.

@huan
Copy link
Member

huan commented Apr 30, 2018

I had changed some of the API to throw Exception when failed, and will changes others in the future.

Please let me know if you found any API need to refactor in the latest version of the master branch, PR will be awesome and welcome!

See: #1167

@huan huan closed this as completed Apr 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants