1
0
mirror of https://github.com/alice-lg/alice-lg.git synced 2024-05-11 05:55:03 +00:00

96 lines
2.2 KiB
React
Raw Normal View History

2018-08-05 18:39:11 +02:00
import _ from 'underscore'
2017-05-16 13:34:00 +02:00
import React from 'react'
import {connect} from 'react-redux'
import {resetApiError} from './actions'
2018-08-05 18:39:11 +02:00
import {infoFromError} from './utils'
2017-05-16 13:34:00 +02:00
class ErrorsPage extends React.Component {
resetApiError() {
this.props.dispatch(resetApiError());
}
render() {
if (!this.props.error) {
return null;
}
let status = null;
if (this.props.error.response) {
status = this.props.error.response.status;
2018-08-05 19:00:27 +02:00
} else {
status = 600;
2017-05-16 13:34:00 +02:00
}
2018-08-05 19:00:27 +02:00
2017-05-16 13:34:00 +02:00
if (!status || (status != 429 && status < 500)) {
return null;
}
let body = null;
2018-08-05 18:39:11 +02:00
// Find affected routeserver
let rs = null;
2018-08-05 19:00:27 +02:00
const errorInfo = infoFromError(this.props.error);
if (errorInfo) {
const rsId = errorInfo.routeserver_id;
if (rsId !== null) {
rs = _.findWhere(this.props.routeservers, { id: rsId });
}
2018-08-05 18:39:11 +02:00
}
2017-05-16 13:34:00 +02:00
if (status == 429) {
body = (
<div className="error-message">
2017-05-22 15:22:25 +02:00
<p>Alice reached the request limit.</p>
2017-05-16 13:34:00 +02:00
<p>We suggest you try at a less busy time.</p>
</div>
);
} else {
2018-08-05 18:39:11 +02:00
let errorStatus = "";
if (this.props.error.response) {
errorStatus = " (got HTTP " + this.props.error.response.status + ")";
}
if (errorInfo) {
errorStatus = ` (got ${errorInfo.tag})`;
}
2017-05-16 13:34:00 +02:00
body = (
<div className="error-message">
<p>
2018-08-05 18:39:11 +02:00
Alice has trouble connecting to the API
{rs &&
<span> of <b>{rs.name}</b></span>}
{errorStatus}
2017-05-16 13:34:00 +02:00
.
</p>
<p>If this problem persist, we suggest you try again later.</p>
</div>
);
}
return (
<div className="error-notify">
2018-08-05 18:39:11 +02:00
<div className="error-dismiss">
<i className="fa fa-times-circle" aria-hidden="true"
onClick={() => this.resetApiError()}></i>
</div>
2017-05-16 13:34:00 +02:00
<div className="error-icon">
<i className="fa fa-times-circle" aria-hidden="true"></i>
</div>
{body}
</div>
);
}
}
export default connect(
(state) => ({
2018-08-05 18:39:11 +02:00
error: state.errors.error,
2018-12-09 18:47:40 +01:00
routeservers: state.routeservers.byId,
2017-05-16 13:34:00 +02:00
})
)(ErrorsPage);