diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index cf3ba51bde..0c3fb21deb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -463,68 +463,94 @@ public class SubscriptionManagerImpl implements SubscriptionManager { throws ApplicationManagementException { try { //todo rethink and modify the {@link App} usage - App app = new App(); - MobileAppTypes mobileAppType = MobileAppTypes.valueOf(application.getType()); - if (DeviceTypes.ANDROID.toString().equalsIgnoreCase(deviceType)) { + if (ApplicationType.CUSTOM.toString().equalsIgnoreCase(application.getType())) { + ProfileOperation operation = new ProfileOperation(); if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { - app.setType(mobileAppType); - app.setLocation(application.getApplicationReleases().get(0).getInstallerPath()); - return MDMAndroidOperationUtil.createInstallAppOperation(app); + operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_INSTALL_APPLICATION); + operation.setType(Operation.Type.PROFILE); + CustomApplication customApplication = new CustomApplication(); + customApplication.setType(application.getType()); + customApplication.setUrl(application.getApplicationReleases().get(0).getInstallerPath()); + operation.setPayLoad(customApplication.toJSON()); + return operation; } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { - return MDMAndroidOperationUtil.createAppUninstallOperation(app); - } else { - String msg = "Invalid Action is found. Action: " + action; - log.error(msg); - throw new ApplicationManagementException(msg); - } - } else if (DeviceTypes.IOS.toString().equalsIgnoreCase(deviceType)) { - if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { - String plistDownloadEndpoint = APIUtil.getArtifactDownloadBaseURL() - + MDMAppConstants.IOSConstants.PLIST + Constants.FORWARD_SLASH - + application.getApplicationReleases().get(0).getUuid(); - app.setType(mobileAppType); - app.setLocation(plistDownloadEndpoint); - Properties properties = new Properties(); - properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true); - properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true); - app.setProperties(properties); - return MDMIOSOperationUtil.createInstallAppOperation(app); - } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { - return MDMIOSOperationUtil.createAppUninstallOperation(app); + operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_UNINSTALL_APPLICATION); + operation.setType(Operation.Type.PROFILE); + CustomApplication customApplication = new CustomApplication(); + customApplication.setType(application.getType()); + //todo get application package name and set + operation.setPayLoad(customApplication.toJSON()); + return operation; } else { String msg = "Invalid Action is found. Action: " + action; log.error(msg); throw new ApplicationManagementException(msg); } } else { - if (ApplicationType.CUSTOM.toString().equalsIgnoreCase(application.getType())) { + App app = new App(); + MobileAppTypes mobileAppType = MobileAppTypes.valueOf(application.getType()); + if (DeviceTypes.ANDROID.toString().equalsIgnoreCase(deviceType)) { if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { - ProfileOperation operation = new ProfileOperation(); - operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_INSTALL_APPLICATION); - operation.setType(Operation.Type.PROFILE); - CustomApplication customApplication = new CustomApplication(); - customApplication.setType(application.getType()); - customApplication.setUrl(application.getApplicationReleases().get(0).getInstallerPath()); - operation.setPayLoad(customApplication.toJSON()); - return operation; + app.setType(mobileAppType); + app.setLocation(application.getApplicationReleases().get(0).getInstallerPath()); + return MDMAndroidOperationUtil.createInstallAppOperation(app); } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { - ProfileOperation operation = new ProfileOperation(); - operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_UNINSTALL_APPLICATION); - operation.setType(Operation.Type.PROFILE); - CustomApplication customApplication = new CustomApplication(); - customApplication.setType(application.getType()); - //todo get application package name and set - operation.setPayLoad(customApplication.toJSON()); return MDMAndroidOperationUtil.createAppUninstallOperation(app); } else { String msg = "Invalid Action is found. Action: " + action; log.error(msg); throw new ApplicationManagementException(msg); } + } else if (DeviceTypes.IOS.toString().equalsIgnoreCase(deviceType)) { + if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { + String plistDownloadEndpoint = + APIUtil.getArtifactDownloadBaseURL() + MDMAppConstants.IOSConstants.PLIST + + Constants.FORWARD_SLASH + application.getApplicationReleases().get(0) + .getUuid(); + app.setType(mobileAppType); + app.setLocation(plistDownloadEndpoint); + Properties properties = new Properties(); + properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true); + properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true); + app.setProperties(properties); + return MDMIOSOperationUtil.createInstallAppOperation(app); + } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { + return MDMIOSOperationUtil.createAppUninstallOperation(app); + } else { + String msg = "Invalid Action is found. Action: " + action; + log.error(msg); + throw new ApplicationManagementException(msg); + } } else { - String msg = "Invalid device type is found. Device Type: " + deviceType; - log.error(msg); - throw new ApplicationManagementException(msg); + if (ApplicationType.CUSTOM.toString().equalsIgnoreCase(application.getType())) { + if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { + ProfileOperation operation = new ProfileOperation(); + operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_INSTALL_APPLICATION); + operation.setType(Operation.Type.PROFILE); + CustomApplication customApplication = new CustomApplication(); + customApplication.setType(application.getType()); + customApplication.setUrl(application.getApplicationReleases().get(0).getInstallerPath()); + operation.setPayLoad(customApplication.toJSON()); + return operation; + } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { + ProfileOperation operation = new ProfileOperation(); + operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_UNINSTALL_APPLICATION); + operation.setType(Operation.Type.PROFILE); + CustomApplication customApplication = new CustomApplication(); + customApplication.setType(application.getType()); + //todo get application package name and set + operation.setPayLoad(customApplication.toJSON()); + return MDMAndroidOperationUtil.createAppUninstallOperation(app); + } else { + String msg = "Invalid Action is found. Action: " + action; + log.error(msg); + throw new ApplicationManagementException(msg); + } + } else { + String msg = "Invalid device type is found. Device Type: " + deviceType; + log.error(msg); + throw new ApplicationManagementException(msg); + } } } } catch (UnknownApplicationTypeException e) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/AppList.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/AppList.js index e6e459e3dc..241ea12acd 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/AppList.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/AppList.js @@ -21,6 +21,7 @@ import AppCard from "./AppCard"; import {Col, message, notification, Row, Result, Skeleton} from "antd"; import axios from "axios"; import {withConfigContext} from "../../context/ConfigContext"; +import {handleApiError} from "../../js/Utils"; class AppList extends React.Component { constructor(props) { @@ -72,20 +73,7 @@ class AppList extends React.Component { } }).catch((error) => { - console.log(error.response); - if (error.hasOwnProperty("response") && error.response.status === 401) { - //todo display a popup with error - message.error('You are not logged in'); - window.location.href = window.location.origin+ '/store/login'; - } else { - notification["error"]({ - message: "There was a problem", - duration: 0, - description: - "Error occurred while trying to load apps.", - }); - } - + handleApiError(error,"Error occurred while trying to load apps."); this.setState({loading: false}); }); }; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/DetailedRating.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/DetailedRating.js index 0536e966cf..aac62976b7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/DetailedRating.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/DetailedRating.js @@ -17,11 +17,12 @@ */ import React from "react"; -import {Row, Typography, Icon} from "antd"; +import {Row, Typography, Icon, notification} from "antd"; import StarRatings from "react-star-ratings"; import "./DetailedRating.css"; import axios from "axios"; import {withConfigContext} from "../../../context/ConfigContext"; +import {handleApiError} from "../../../js/Utils"; const { Text } = Typography; @@ -62,9 +63,7 @@ class DetailedRating extends React.Component{ } }).catch(function (error) { - if (error.response.status === 401) { - window.location.href = window.location.origin+'/store/login'; - } + handleApiError(error,"Error occurred while trying to load ratings."); }); }; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js index 6d55b45361..d2b45a191c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js @@ -27,6 +27,7 @@ import axios from "axios"; import AppInstallModal from "./install/AppInstallModal"; import CurrentUsersReview from "./review/CurrentUsersReview"; import {withConfigContext} from "../../../context/ConfigContext"; +import {handleApiError} from "../../../js/Utils"; const {Title, Text, Paragraph} = Typography; @@ -78,20 +79,7 @@ class ReleaseView extends React.Component { } }).catch((error) => { - if (error.response.status === 401) { - window.location.href = window.location.origin+ '/store/login'; - } else { - this.setState({ - loading: false, - visible: false - }); - notification["error"]({ - message: "There was a problem", - duration: 0, - description: - "Error occurred while installing the app.", - }); - } + handleApiError(error,"Error occurred while installing the app."); }); }; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/DeviceInstall.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/DeviceInstall.js index 2af6be7a74..4b7f11bbd2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/DeviceInstall.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/DeviceInstall.js @@ -24,6 +24,7 @@ import TimeAgo from 'javascript-time-ago' // Load locale-specific relative date/time formatting rules. import en from 'javascript-time-ago/locale/en' import {withConfigContext} from "../../../../context/ConfigContext"; +import {handleApiError} from "../../../../js/Utils"; const {Text} = Typography; const columns = [ @@ -166,20 +167,7 @@ class DeviceInstall extends React.Component { } }).catch((error) => { - console.log(error); - if (error.hasOwnProperty("status") && error.response.status === 401) { - //todo display a popop with error - message.error('You are not logged in'); - window.location.href = window.location.origin + '/store/login'; - } else { - notification["error"]({ - message: "There was a problem", - duration: 0, - description: - "Error occurred while trying to load devices.", - }); - } - + handleApiError(error,"Error occurred while trying to load devices."); this.setState({loading: false}); }); }; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/GroupInstall.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/GroupInstall.js index a8af7482c9..44024687a2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/GroupInstall.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/GroupInstall.js @@ -21,6 +21,7 @@ import {Typography, Select, Spin, message, notification, Button} from "antd"; import debounce from 'lodash.debounce'; import axios from "axios"; import {withConfigContext} from "../../../../context/ConfigContext"; +import {handleApiError} from "../../../../js/Utils"; const {Text} = Typography; const {Option} = Select; @@ -64,19 +65,8 @@ class GroupInstall extends React.Component { this.setState({data, fetching: false}); } - }).catch((error) => { console.log(error); - if (error.hasOwnProperty("status") && error.response.status === 401) { - message.error('You are not logged in'); - window.location.href = window.location.origin+'/store/login'; - } else { - notification["error"]({ - message: "There was a problem", - duration: 0, - description: - "Error occurred while trying to load groups.", - }); - } - + }).catch((error) => { + handleApiError(error,"Error occurred while trying to load groups."); this.setState({fetching: false}); }); }; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/RoleInstall.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/RoleInstall.js index 877fd3a4cb..0f6da0f2d7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/RoleInstall.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/RoleInstall.js @@ -21,6 +21,7 @@ import {Typography, Select, Spin, message, notification, Button} from "antd"; import debounce from 'lodash.debounce'; import axios from "axios"; import {withConfigContext} from "../../../../context/ConfigContext"; +import {handleApiError} from "../../../../js/Utils"; const {Text} = Typography; const {Option} = Select; @@ -64,19 +65,8 @@ class RoleInstall extends React.Component { this.setState({data, fetching: false}); } - }).catch((error) => { console.log(error); - if (error.hasOwnProperty("status") && error.response.status === 401) { - message.error('You are not logged in'); - window.location.href = window.location.origin+'/store/login'; - } else { - notification["error"]({ - message: "There was a problem", - duration: 0, - description: - "Error occurred while trying to load roles.", - }); - } - + }).catch((error) => { + handleApiError(error,"Error occurred while trying to load roles."); this.setState({fetching: false}); }); }; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/UserInstall.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/UserInstall.js index 8e592d52cf..d04d11a24c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/UserInstall.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/UserInstall.js @@ -21,6 +21,7 @@ import {Typography, Select, Spin, message, notification, Button} from "antd"; import debounce from 'lodash.debounce'; import axios from "axios"; import {withConfigContext} from "../../../../context/ConfigContext"; +import {handleApiError} from "../../../../js/Utils"; const {Text} = Typography; const {Option} = Select; @@ -67,18 +68,7 @@ class UserInstall extends React.Component { } }).catch((error) => { - if (error.response.hasOwnProperty(status) && error.response.status === 401) { - message.error('You are not logged in'); - window.location.href = window.location.origin+ '/store/login'; - } else { - notification["error"]({ - message: "There was a problem", - duration: 0, - description: - "Error occurred while trying to load users.", - }); - } - + handleApiError(error,"Error occurred while trying to load users."); this.setState({fetching: false}); }); }; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/AddReview.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/AddReview.js index ee2b8f65ff..e30cac30bb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/AddReview.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/AddReview.js @@ -21,6 +21,7 @@ import {Drawer, Button, Icon, Row, Col, Typography, Divider, Input, Spin, notifi import StarRatings from "react-star-ratings"; import axios from "axios"; import {withConfigContext} from "../../../../context/ConfigContext"; +import {handleApiError} from "../../../../js/Utils"; const {Title} = Typography; const {TextArea} = Input; @@ -103,20 +104,11 @@ class AddReview extends React.Component { } }).catch((error) => { - if (error.response.status === 401) { - window.location.href = window.location.origin+ '/store/login'; - } else { - this.setState({ - loading: false, - visible: false - }); - notification["error"]({ - message: "There was a problem", - duration: 0, - description: - "We are unable to add your review right now.", - }); - } + handleApiError(error,"We are unable to add your review right now."); + this.setState({ + loading: false, + visible: false + }); }); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/CurrentUsersReview.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/CurrentUsersReview.js index ed1f14711c..2173db1921 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/CurrentUsersReview.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/CurrentUsersReview.js @@ -22,6 +22,7 @@ import SingleReview from "./singleReview/SingleReview"; import axios from "axios"; import AddReview from "./AddReview"; import {withConfigContext} from "../../../../context/ConfigContext"; +import {handleApiError} from "../../../../js/Utils"; const {Text, Paragraph} = Typography; @@ -52,17 +53,7 @@ class CurrentUsersReview extends React.Component { } }).catch((error) => { - if (error.response.hasOwnProperty(status) && error.response.status === 401) { - message.error('You are not logged in'); - window.location.href = window.location.origin+ '/store/login'; - } else { - notification["error"]({ - message: "There was a problem", - duration: 0, - description: - "Error occurred while trying to get your review.", - }); - } + handleApiError(error,"Error occurred while trying to get your review."); }); }; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/Reviews.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/Reviews.js index ca0e84567c..59020a26d6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/Reviews.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/Reviews.js @@ -24,6 +24,7 @@ import InfiniteScroll from 'react-infinite-scroller'; import SingleReview from "./singleReview/SingleReview"; import axios from "axios"; import {withConfigContext} from "../../../../context/ConfigContext"; +import {handleApiError} from "../../../../js/Utils"; const limit = 5; @@ -60,16 +61,7 @@ class Reviews extends React.Component { } }).catch(function (error) { - if (error.response.status === 401) { - window.location.href = window.location.origin+ '/store/login'; - } else { - notification["error"]({ - message: "There was a problem", - duration: 0, - description: - "Error occurred while trying to load reviews.", - }); - } + handleApiError(error,"Error occurred while trying to load reviews."); }); }; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/singleReview/SingleReview.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/singleReview/SingleReview.js index 29f44b1a68..fe6ae73b9e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/singleReview/SingleReview.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/singleReview/SingleReview.js @@ -25,6 +25,7 @@ import "./SingleReview.css"; import EditReview from "./editReview/EditReview"; import axios from "axios"; import {withConfigContext} from "../../../../../context/ConfigContext"; +import {handleApiError} from "../../../../../js/Utils"; const {Text, Paragraph} = Typography; const colorList = ['#f0932b', '#badc58', '#6ab04c', '#eb4d4b', '#0abde3', '#9b59b6', '#3498db', '#22a6b3', '#e84393', '#f9ca24']; @@ -78,17 +79,7 @@ class SingleReview extends React.Component { this.props.deleteCallback(id); } }).catch((error) => { - console.log(error); - if (error.hasOwnProperty("response") && error.response.status === 401) { - window.location.href = window.location.origin+ '/store/login'; - } else { - notification["error"]({ - message: "There was a problem", - duration: 0, - description: - "We were unable to delete the review..", - }); - } + handleApiError(error,"We were unable to delete the review.."); }); }; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/singleReview/editReview/EditReview.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/singleReview/editReview/EditReview.js index f18bac5079..67dd8c7c2d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/singleReview/editReview/EditReview.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/singleReview/editReview/EditReview.js @@ -22,6 +22,7 @@ import StarRatings from "react-star-ratings"; import axios from "axios"; import "./EditReview.css"; import {withConfigContext} from "../../../../../../context/ConfigContext"; +import {handleApiError} from "../../../../../../js/Utils"; const {Title} = Typography; const {TextArea} = Input; @@ -115,21 +116,11 @@ class EditReview extends React.Component { } }).catch((error) => { - console.log(error); - if (error.hasOwnProperty("response") && error.response.status === 401) { - window.location.href = window.location.origin+ '/store/login'; - } else { - this.setState({ - loading: false, - visible: false - }); - notification["error"]({ - message: "There was a problem", - duration: 0, - description: - "We are unable to add your review right now.", - }); - } + handleApiError(error,"We are unable to add your review right now."); + this.setState({ + loading: false, + visible: false + }); }); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/js/Utils.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/js/Utils.js new file mode 100644 index 0000000000..7a51083453 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/js/Utils.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import {notification} from "antd"; + +export const handleApiError = (error, message) => { + console.log(error); + if (error.hasOwnProperty("response") && error.response.status === 401) { + window.location.href = window.location.origin + '/store/login'; + } else { + notification["error"]({ + message: "There was a problem", + duration: 0, + description: message, + }); + } +}; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/Login.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/Login.js index 5aed47a3b4..ec615bfedf 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/Login.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/Login.js @@ -21,6 +21,7 @@ import {Typography, Row, Col, Form, Icon, Input, Button, Checkbox} from 'antd'; import './Login.css'; import axios from 'axios'; import {withConfigContext} from "../context/ConfigContext"; +import {handleApiError} from "../js/Utils"; const {Title} = Typography; const {Text} = Typography; @@ -104,7 +105,8 @@ class NormalLoginForm extends React.Component { window.location = window.location.origin+ "/store"; } }).catch(function (error) { - if (error.response.status === 400) { + handleApiError(error,"Error occurred while trying to load groups."); + if (error.hasOwnProperty("response") && error.response.status === 400) { thisForm.setState({ inValid: true, loading: false diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/Dashboard.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/Dashboard.js index e59b58d990..044dae5378 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/Dashboard.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/Dashboard.js @@ -26,6 +26,7 @@ import axios from "axios"; import "./Dashboard.css"; import {withConfigContext} from "../../context/ConfigContext"; import Logout from "./logout/Logout"; +import {handleApiError} from "../../js/Utils"; const {SubMenu} = Menu; @@ -58,16 +59,7 @@ class Dashboard extends React.Component { } }).catch((error) => { - if (error.hasOwnProperty("response") && error.response.status === 401) { - window.location.href = window.location.origin + '/store/login'; - } else { - notification["error"]({ - message: "There was a problem", - duration: 0, - description: - "Error occurred while trying to load device types.", - }); - } + handleApiError(error,"Error occurred while trying to load device types."); this.setState({ loading: false }); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/apps/release/Release.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/apps/release/Release.js index b1eb744b22..adac67e737 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/apps/release/Release.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/apps/release/Release.js @@ -23,6 +23,7 @@ import ReleaseView from "../../../../components/apps/release/ReleaseView"; import axios from "axios"; import {withConfigContext} from "../../../../context/ConfigContext"; import {Link} from "react-router-dom"; +import {handleApiError} from "../../../../js/Utils"; const {Title} = Typography; @@ -71,20 +72,7 @@ class Release extends React.Component { } }).catch((error) => { - console.log(error); - if (error.hasOwnProperty("response") && error.response.status === 401) { - //todo display a popop with error - message.error('You are not logged in'); - window.location.href = window.location.origin + '/store/login'; - } else { - notification["error"]({ - message: "There was a problem", - duration: 0, - description: - "Error occurred while trying to load releases.", - }); - } - + handleApiError(error,"Error occurred while trying to load releases."); this.setState({loading: false}); }); }; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/logout/Logout.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/logout/Logout.js index 35068cc581..87c57bc014 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/logout/Logout.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/logout/Logout.js @@ -20,6 +20,7 @@ import React from "react"; import {notification, Menu, Icon} from 'antd'; import axios from 'axios'; import {withConfigContext} from "../../../context/ConfigContext"; +import {handleApiError} from "../../../js/Utils"; /* This class for call the logout api by sending request @@ -52,19 +53,7 @@ class Logout extends React.Component { window.location = window.location.origin + "/store/login"; } }).catch(function (error) { - - if (error.hasOwnProperty("response") && error.response.status === 400) { - thisForm.setState({ - inValid: true - }); - } else { - notification["error"]({ - message: "There was a problem", - duration: 0, - description: - "Error occurred while trying to logout.", - }); - } + handleApiError(error,"Error occurred while trying to get your review."); }); };