diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/operation-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/operation-api.jag index 7465f21649..ac30769bb4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/operation-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/operation-api.jag @@ -51,7 +51,12 @@ if (uriMatcher.match("/{context}/api/operation/paginate")) { } else { response["status"] = restAPIResponse["status"]; if (restAPIResponse["responseText"]) { - response["content"] = parse(restAPIResponse["responseText"]); + var responseText = ""; + try { + response["content"] = parse(restAPIResponse["responseText"]); + } catch (e) { + responseText = restAPIResponse["responseText"]; + } } } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js index 1600618775..673c3e199f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js @@ -45,12 +45,13 @@ var invokers = function () { * If the token pair is not set in the session, this will return null. */ privateMethods.getAccessToken = function () { - var tokenPair = session.get(constants["TOKEN_PAIR"]); - if (tokenPair) { - return parse(tokenPair)["accessToken"]; - } else { - return null; + if (session) { + var tokenPair = session.get(constants["TOKEN_PAIR"]); + if (tokenPair) { + return parse(tokenPair)["accessToken"]; + } } + return null; }; /** @@ -80,9 +81,10 @@ var invokers = function () { if (devicemgtProps["isOAuthEnabled"]) { var accessToken = privateMethods.getAccessToken(); - if (!accessToken) { + if (accessToken == null) { userModule.logout(function () { response.sendRedirect(devicemgtProps["appContext"] + "login"); + return responseCallback({"status": 401, "responseText" : "Session expired!"}); }); } else { xmlHttpRequest.setRequestHeader(constants["AUTHORIZATION_HEADER"],