mirror of
https://github.com/getredash/redash.git
synced 2025-12-25 01:03:20 -05:00
* Added screen reader CSS * Added description to external links * Added spinner icon accessibility * Added accessibility to exclamation and big message * Added question and exclamation accessibility * Hide decorative icons * Standardized link design * Added a11y to refresh icons * Added aria-label to anchors and buttons * Added a11y to conditional icons * Added applicable labels to Ant Icons * Changed escape to interpolation * Replaced external links with opens in new tab * Improved Tooltip hosts * Added aria live to temporary elements * Removed mistakenly added redundant helper * Undoes unnecessarily added interpolation * Replaced empty label with hidden * Improved full icon label * Improved display of live regions * Added note * remove unused class * Created unique id * Remove TODOs * Proper action label * Improved feedback for autocomplete toggle * feature: add id hook * refactor: use id hook * standardize white space
70 lines
1.9 KiB
JavaScript
70 lines
1.9 KiB
JavaScript
import { get, isObject } from "lodash";
|
||
import React from "react";
|
||
import PropTypes from "prop-types";
|
||
|
||
import "./ErrorMessage.less";
|
||
import DynamicComponent from "@/components/DynamicComponent";
|
||
import { ErrorMessageDetails } from "@/components/ApplicationArea/ErrorMessageDetails";
|
||
|
||
function getErrorMessageByStatus(status, defaultMessage) {
|
||
switch (status) {
|
||
case 404:
|
||
return "It seems like the page you're looking for cannot be found.";
|
||
case 401:
|
||
case 403:
|
||
return "It seems like you don’t have permission to see this page.";
|
||
default:
|
||
return defaultMessage;
|
||
}
|
||
}
|
||
|
||
function getErrorMessage(error) {
|
||
const message = "It seems like we encountered an error. Try refreshing this page or contact your administrator.";
|
||
if (isObject(error)) {
|
||
// HTTP errors
|
||
if (error.isAxiosError && isObject(error.response)) {
|
||
return getErrorMessageByStatus(error.response.status, get(error, "response.data.message", message));
|
||
}
|
||
// Router errors
|
||
if (error.status) {
|
||
return getErrorMessageByStatus(error.status, message);
|
||
}
|
||
}
|
||
return message;
|
||
}
|
||
|
||
export default function ErrorMessage({ error, message }) {
|
||
if (!error) {
|
||
return null;
|
||
}
|
||
|
||
console.error(error);
|
||
|
||
const errorDetailsProps = {
|
||
error,
|
||
message: message || getErrorMessage(error),
|
||
};
|
||
|
||
return (
|
||
<div className="error-message-container" data-test="ErrorMessage" role="alert">
|
||
<div className="error-state bg-white tiled">
|
||
<div className="error-state__icon">
|
||
<i className="zmdi zmdi-alert-circle-o" aria-hidden="true" />
|
||
</div>
|
||
<div className="error-state__details">
|
||
<DynamicComponent
|
||
name="ErrorMessageDetails"
|
||
fallback={<ErrorMessageDetails {...errorDetailsProps} />}
|
||
{...errorDetailsProps}
|
||
/>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
ErrorMessage.propTypes = {
|
||
error: PropTypes.object.isRequired,
|
||
message: PropTypes.string,
|
||
};
|