Skip to content

当传入的 user-agent 不是字符串的时候,内部没有处理,导致抛出脚本错误#21

Open
norfish wants to merge 0 commit intofex-team:masterfrom
norfish:master
Open

当传入的 user-agent 不是字符串的时候,内部没有处理,导致抛出脚本错误#21
norfish wants to merge 0 commit intofex-team:masterfrom
norfish:master

Conversation

@norfish
Copy link
Copy Markdown

@norfish norfish commented Apr 18, 2017

ua的参数不是正常的 user-agent 字符串的时候,new UA 会直接抛出脚本错误,这次修改对非字符串的参数做了兼容,当传入非法参数的时候静默返回,确保decect结果可以正常使用

另外这一行我不确定要不要加上 // throw new TypeError('ua must be a string')
是否需要抛出一个自定义的Type Error出来,我倾向于不抛出来。因为ua-device是个第三方库,应该对用户传入的参数做各种兼容处理,而不是直接抛出错误,导致用户进程 crash 掉

@norfish norfish changed the title 当传入的 user-agent 不是字符串的时候,没有处理,会抛出脚本错误 当传入的 user-agent 不是字符串的时候,内部没有处理,导致抛出脚本错误 Apr 18, 2017
@kevindu1993
Copy link
Copy Markdown
Contributor

嗯,你说的很对,确实没有注意数据类型判断的问题,平时我在用它的时候是在外层包的try catch,所以就没在内部进行对应的处理

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants