mirror of
https://github.com/getredash/redash.git
synced 2026-03-23 13:00:10 -04:00
* DynamicComponent for QuerySourceAlerts * General Settings updates * Dynamic Date[Range] updates * EmptyState updates * Query and SchemaBrowser updates * Adjust page headers and add disablePublish * Policy updates * Separate Home FavoritesList component * Update FormatQuery * Autolimit frontend fixes * Misc updates * Keep registering of QuerySourceDropdown * Undo changes in DynamicComponent * Change sql-formatter package.json syntax * Allow opening help trigger in new tab * Don't run npm commands as root in Dockerfile * Cypress: Remove extra execute query
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" />
|
||
</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,
|
||
};
|