Merge branch 'application-mgt-new' into 'application-mgt-new'

Handle API error in APPM store

See merge request entgra/carbon-device-mgt!254
feature/appm-store/pbac
Dharmakeerthi Lasantha 5 years ago
commit fd7436eaa6

@ -21,6 +21,7 @@ import AppCard from "./AppCard";
import {Col, message, notification, Row, Result, Skeleton} from "antd"; import {Col, message, notification, Row, Result, Skeleton} from "antd";
import axios from "axios"; import axios from "axios";
import {withConfigContext} from "../../context/ConfigContext"; import {withConfigContext} from "../../context/ConfigContext";
import {handleApiError} from "../../js/Utils";
class AppList extends React.Component { class AppList extends React.Component {
constructor(props) { constructor(props) {
@ -72,20 +73,7 @@ class AppList extends React.Component {
} }
}).catch((error) => { }).catch((error) => {
console.log(error.response); handleApiError(error,"Error occurred while trying to load apps.");
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.",
});
}
this.setState({loading: false}); this.setState({loading: false});
}); });
}; };

@ -17,11 +17,12 @@
*/ */
import React from "react"; import React from "react";
import {Row, Typography, Icon} from "antd"; import {Row, Typography, Icon, notification} from "antd";
import StarRatings from "react-star-ratings"; import StarRatings from "react-star-ratings";
import "./DetailedRating.css"; import "./DetailedRating.css";
import axios from "axios"; import axios from "axios";
import {withConfigContext} from "../../../context/ConfigContext"; import {withConfigContext} from "../../../context/ConfigContext";
import {handleApiError} from "../../../js/Utils";
const { Text } = Typography; const { Text } = Typography;
@ -62,9 +63,7 @@ class DetailedRating extends React.Component{
} }
}).catch(function (error) { }).catch(function (error) {
if (error.response.status === 401) { handleApiError(error,"Error occurred while trying to load ratings.");
window.location.href = window.location.origin+'/store/login';
}
}); });
}; };

@ -27,6 +27,7 @@ import axios from "axios";
import AppInstallModal from "./install/AppInstallModal"; import AppInstallModal from "./install/AppInstallModal";
import CurrentUsersReview from "./review/CurrentUsersReview"; import CurrentUsersReview from "./review/CurrentUsersReview";
import {withConfigContext} from "../../../context/ConfigContext"; import {withConfigContext} from "../../../context/ConfigContext";
import {handleApiError} from "../../../js/Utils";
const {Title, Text, Paragraph} = Typography; const {Title, Text, Paragraph} = Typography;
@ -78,20 +79,7 @@ class ReleaseView extends React.Component {
} }
}).catch((error) => { }).catch((error) => {
if (error.response.status === 401) { handleApiError(error,"Error occurred while installing the app.");
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.",
});
}
}); });
}; };

@ -24,6 +24,7 @@ import TimeAgo from 'javascript-time-ago'
// Load locale-specific relative date/time formatting rules. // Load locale-specific relative date/time formatting rules.
import en from 'javascript-time-ago/locale/en' import en from 'javascript-time-ago/locale/en'
import {withConfigContext} from "../../../../context/ConfigContext"; import {withConfigContext} from "../../../../context/ConfigContext";
import {handleApiError} from "../../../../js/Utils";
const {Text} = Typography; const {Text} = Typography;
const columns = [ const columns = [
@ -166,20 +167,7 @@ class DeviceInstall extends React.Component {
} }
}).catch((error) => { }).catch((error) => {
console.log(error); handleApiError(error,"Error occurred while trying to load devices.");
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.",
});
}
this.setState({loading: false}); this.setState({loading: false});
}); });
}; };

@ -21,6 +21,7 @@ import {Typography, Select, Spin, message, notification, Button} from "antd";
import debounce from 'lodash.debounce'; import debounce from 'lodash.debounce';
import axios from "axios"; import axios from "axios";
import {withConfigContext} from "../../../../context/ConfigContext"; import {withConfigContext} from "../../../../context/ConfigContext";
import {handleApiError} from "../../../../js/Utils";
const {Text} = Typography; const {Text} = Typography;
const {Option} = Select; const {Option} = Select;
@ -64,19 +65,8 @@ class GroupInstall extends React.Component {
this.setState({data, fetching: false}); this.setState({data, fetching: false});
} }
}).catch((error) => { console.log(error); }).catch((error) => {
if (error.hasOwnProperty("status") && error.response.status === 401) { handleApiError(error,"Error occurred while trying to load groups.");
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.",
});
}
this.setState({fetching: false}); this.setState({fetching: false});
}); });
}; };

@ -21,6 +21,7 @@ import {Typography, Select, Spin, message, notification, Button} from "antd";
import debounce from 'lodash.debounce'; import debounce from 'lodash.debounce';
import axios from "axios"; import axios from "axios";
import {withConfigContext} from "../../../../context/ConfigContext"; import {withConfigContext} from "../../../../context/ConfigContext";
import {handleApiError} from "../../../../js/Utils";
const {Text} = Typography; const {Text} = Typography;
const {Option} = Select; const {Option} = Select;
@ -64,19 +65,8 @@ class RoleInstall extends React.Component {
this.setState({data, fetching: false}); this.setState({data, fetching: false});
} }
}).catch((error) => { console.log(error); }).catch((error) => {
if (error.hasOwnProperty("status") && error.response.status === 401) { handleApiError(error,"Error occurred while trying to load roles.");
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.",
});
}
this.setState({fetching: false}); this.setState({fetching: false});
}); });
}; };

@ -21,6 +21,7 @@ import {Typography, Select, Spin, message, notification, Button} from "antd";
import debounce from 'lodash.debounce'; import debounce from 'lodash.debounce';
import axios from "axios"; import axios from "axios";
import {withConfigContext} from "../../../../context/ConfigContext"; import {withConfigContext} from "../../../../context/ConfigContext";
import {handleApiError} from "../../../../js/Utils";
const {Text} = Typography; const {Text} = Typography;
const {Option} = Select; const {Option} = Select;
@ -67,18 +68,7 @@ class UserInstall extends React.Component {
} }
}).catch((error) => { }).catch((error) => {
if (error.response.hasOwnProperty(status) && error.response.status === 401) { handleApiError(error,"Error occurred while trying to load users.");
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.",
});
}
this.setState({fetching: false}); this.setState({fetching: false});
}); });
}; };

@ -21,6 +21,7 @@ import {Drawer, Button, Icon, Row, Col, Typography, Divider, Input, Spin, notifi
import StarRatings from "react-star-ratings"; import StarRatings from "react-star-ratings";
import axios from "axios"; import axios from "axios";
import {withConfigContext} from "../../../../context/ConfigContext"; import {withConfigContext} from "../../../../context/ConfigContext";
import {handleApiError} from "../../../../js/Utils";
const {Title} = Typography; const {Title} = Typography;
const {TextArea} = Input; const {TextArea} = Input;
@ -103,20 +104,11 @@ class AddReview extends React.Component {
} }
}).catch((error) => { }).catch((error) => {
if (error.response.status === 401) { handleApiError(error,"We are unable to add your review right now.");
window.location.href = window.location.origin+ '/store/login';
} else {
this.setState({ this.setState({
loading: false, loading: false,
visible: false visible: false
}); });
notification["error"]({
message: "There was a problem",
duration: 0,
description:
"We are unable to add your review right now.",
});
}
}); });

@ -22,6 +22,7 @@ import SingleReview from "./singleReview/SingleReview";
import axios from "axios"; import axios from "axios";
import AddReview from "./AddReview"; import AddReview from "./AddReview";
import {withConfigContext} from "../../../../context/ConfigContext"; import {withConfigContext} from "../../../../context/ConfigContext";
import {handleApiError} from "../../../../js/Utils";
const {Text, Paragraph} = Typography; const {Text, Paragraph} = Typography;
@ -52,17 +53,7 @@ class CurrentUsersReview extends React.Component {
} }
}).catch((error) => { }).catch((error) => {
if (error.response.hasOwnProperty(status) && error.response.status === 401) { handleApiError(error,"Error occurred while trying to get your review.");
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.",
});
}
}); });
}; };

@ -24,6 +24,7 @@ import InfiniteScroll from 'react-infinite-scroller';
import SingleReview from "./singleReview/SingleReview"; import SingleReview from "./singleReview/SingleReview";
import axios from "axios"; import axios from "axios";
import {withConfigContext} from "../../../../context/ConfigContext"; import {withConfigContext} from "../../../../context/ConfigContext";
import {handleApiError} from "../../../../js/Utils";
const limit = 5; const limit = 5;
@ -60,16 +61,7 @@ class Reviews extends React.Component {
} }
}).catch(function (error) { }).catch(function (error) {
if (error.response.status === 401) { handleApiError(error,"Error occurred while trying to load reviews.");
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.",
});
}
}); });
}; };

@ -25,6 +25,7 @@ import "./SingleReview.css";
import EditReview from "./editReview/EditReview"; import EditReview from "./editReview/EditReview";
import axios from "axios"; import axios from "axios";
import {withConfigContext} from "../../../../../context/ConfigContext"; import {withConfigContext} from "../../../../../context/ConfigContext";
import {handleApiError} from "../../../../../js/Utils";
const {Text, Paragraph} = Typography; const {Text, Paragraph} = Typography;
const colorList = ['#f0932b', '#badc58', '#6ab04c', '#eb4d4b', '#0abde3', '#9b59b6', '#3498db', '#22a6b3', '#e84393', '#f9ca24']; 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); this.props.deleteCallback(id);
} }
}).catch((error) => { }).catch((error) => {
console.log(error); handleApiError(error,"We were unable to delete the review..");
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..",
});
}
}); });
}; };

@ -22,6 +22,7 @@ import StarRatings from "react-star-ratings";
import axios from "axios"; import axios from "axios";
import "./EditReview.css"; import "./EditReview.css";
import {withConfigContext} from "../../../../../../context/ConfigContext"; import {withConfigContext} from "../../../../../../context/ConfigContext";
import {handleApiError} from "../../../../../../js/Utils";
const {Title} = Typography; const {Title} = Typography;
const {TextArea} = Input; const {TextArea} = Input;
@ -115,21 +116,11 @@ class EditReview extends React.Component {
} }
}).catch((error) => { }).catch((error) => {
console.log(error); handleApiError(error,"We are unable to add your review right now.");
if (error.hasOwnProperty("response") && error.response.status === 401) {
window.location.href = window.location.origin+ '/store/login';
} else {
this.setState({ this.setState({
loading: false, loading: false,
visible: false visible: false
}); });
notification["error"]({
message: "There was a problem",
duration: 0,
description:
"We are unable to add your review right now.",
});
}
}); });

@ -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,
});
}
};

@ -21,6 +21,7 @@ import {Typography, Row, Col, Form, Icon, Input, Button, Checkbox} from 'antd';
import './Login.css'; import './Login.css';
import axios from 'axios'; import axios from 'axios';
import {withConfigContext} from "../context/ConfigContext"; import {withConfigContext} from "../context/ConfigContext";
import {handleApiError} from "../js/Utils";
const {Title} = Typography; const {Title} = Typography;
const {Text} = Typography; const {Text} = Typography;
@ -104,7 +105,8 @@ class NormalLoginForm extends React.Component {
window.location = window.location.origin+ "/store"; window.location = window.location.origin+ "/store";
} }
}).catch(function (error) { }).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({ thisForm.setState({
inValid: true, inValid: true,
loading: false loading: false

@ -26,6 +26,7 @@ import axios from "axios";
import "./Dashboard.css"; import "./Dashboard.css";
import {withConfigContext} from "../../context/ConfigContext"; import {withConfigContext} from "../../context/ConfigContext";
import Logout from "./logout/Logout"; import Logout from "./logout/Logout";
import {handleApiError} from "../../js/Utils";
const {SubMenu} = Menu; const {SubMenu} = Menu;
@ -58,16 +59,7 @@ class Dashboard extends React.Component {
} }
}).catch((error) => { }).catch((error) => {
if (error.hasOwnProperty("response") && error.response.status === 401) { handleApiError(error,"Error occurred while trying to load device types.");
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.",
});
}
this.setState({ this.setState({
loading: false loading: false
}); });

@ -23,6 +23,7 @@ import ReleaseView from "../../../../components/apps/release/ReleaseView";
import axios from "axios"; import axios from "axios";
import {withConfigContext} from "../../../../context/ConfigContext"; import {withConfigContext} from "../../../../context/ConfigContext";
import {Link} from "react-router-dom"; import {Link} from "react-router-dom";
import {handleApiError} from "../../../../js/Utils";
const {Title} = Typography; const {Title} = Typography;
@ -71,20 +72,7 @@ class Release extends React.Component {
} }
}).catch((error) => { }).catch((error) => {
console.log(error); handleApiError(error,"Error occurred while trying to load releases.");
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.",
});
}
this.setState({loading: false}); this.setState({loading: false});
}); });
}; };

@ -20,6 +20,7 @@ import React from "react";
import {notification, Menu, Icon} from 'antd'; import {notification, Menu, Icon} from 'antd';
import axios from 'axios'; import axios from 'axios';
import {withConfigContext} from "../../../context/ConfigContext"; import {withConfigContext} from "../../../context/ConfigContext";
import {handleApiError} from "../../../js/Utils";
/* /*
This class for call the logout api by sending request 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"; window.location = window.location.origin + "/store/login";
} }
}).catch(function (error) { }).catch(function (error) {
handleApiError(error,"Error occurred while trying to get your review.");
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.",
});
}
}); });
}; };

Loading…
Cancel
Save