Error: Unexpected token u in JSON at position 0

Description

When a user tries to enter retrospective mode for the first time, they see an error stating

"Unexpected token u in JSON at position 0"

Steps to reproduce:
1. Login with some user
2. Inspect ➞ Application ➞ Storage ➞ Cookies ➞ https://product-qa08.mybahmni.org
3. Put `undefined` value for key `app.clinical.grantProviderAccessData`
4. Click on programs module

Whenever the cookie “app:clinical:grantProviderAccessData” is undefined, getting the below error:

Unexpected token u in JSON at position 0

Stacktrace:

Steps to Reproduce:

  • Make sure that the cookie "app:clinical:grantProviderAccessData" is undefined./ login into the system for the first time then "app:clinical:grantProviderAccessData"

  • Go to Retrospective entry. Leave the ‘Enter on behalf’ field empty

  • Change the date and click on OK.

PR here: https://github.com/Bahmni/openmrs-module-bahmniapps/pull/112

Attachments

2

Gliffy Diagrams

Activity

Show:

Arjun Khandelwal July 17, 2018 at 12:23 PM

whatever works. say an empty object {} if that works.

Saikumar Vantaku July 16, 2018 at 12:02 PM

Hi
Thanks for suggesting a better way to fix this. I am a little confused while reading the last lines.
When you said empty, does it an empty string or anything else?

Arjun Khandelwal July 13, 2018 at 7:51 AM
Edited

Hi,
As per our discussion in last PAT call. i tried to understand this issue better.
Below are some observations and thoughts:
What i have seen is when people have the login screen boomarked (e.g. https://demo.mybahmni.org/bahmni/home) and access via that screen and not starting from the home screen, the issue occurs and goes away after deleting cookies but resurfaces after sometime. But if i navigate from the home screen (that is, https://demo.mybahmni.org/), then the issue doesn't happen. Based on this, i think what is happening is that the cookie in discussion gets set with null value from the home screen but not from the login screen.
Looking at the commit related to this card, i see that a null value is returned if value for a cookie is not found which could potentially fix the error user was seeing and move forward.
But may be there could be a better way to fix this:
This cookie is read when the user lands on the retrospective mode and is supposed to be set when user selects "on behalf of". Nothing was being set when on behalf of was empty and so this error.
I think rather than a blanket top level null return to avoid this issue, i would have preferred setting the cookie in question to empty when no provider is selected. so that the code is explicit and app doesn't fail silently in any other scenario.
cc :

laxman manandhar June 21, 2018 at 11:15 AM

Works as expected !

laxman manandhar June 21, 2018 at 11:14 AM

What I find is that , when I manually set the value `undefined` for key `app.clinical.grantProviderAccessData` as mentioned in replication step , the issue is replicated But when I go to the flow of retrospective entry then the problem is not replicated. Its solved.

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

UAT Assignee

Reviewer

Components

Sprint

Fix versions

Priority

Created December 7, 2017 at 11:19 AM
Updated July 17, 2018 at 12:23 PM
Resolved June 21, 2018 at 11:15 AM