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

cookie.get()方法报错 #4

Open
ghost opened this issue Apr 14, 2021 · 1 comment
Open

cookie.get()方法报错 #4

ghost opened this issue Apr 14, 2021 · 1 comment

Comments

@ghost
Copy link

ghost commented Apr 14, 2021

部署在nginx里的项目,cookie.get()方法会报错:
umi.js:1 SyntaxError: Unexpected token G in JSON at position 0
at JSON.parse ()
at Object.get (umi.js:1)
at c (umi.js:1)
at umi.js:1
at Array.forEach ()
at e.value (umi.js:1)
at r (umi.js:1)
at umi.js:1
at ks (umi.js:1)
at Yl (umi.js:1)
部署到tomcat里面没问题,请问这是怎么回事

@sur-create
Copy link

sur-create commented Apr 27, 2022

浏览器cookie里面如果有未进行JSON.stringify转换的键值对就会报错SyntaxError,
可以将obj[key] = isJsonString ? JSON.parse(val) : val 的报错抛出然后继续执行下一次循环就可以了
try { obj[key] = isJsonString ? JSON.parse(val) : val } catch (error) { continue }

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

No branches or pull requests

1 participant