mirror of
https://github.com/apache/superset.git
synced 2026-04-20 08:34:37 +00:00
feat: refactor error components and add database issue code (#10473)
* feat: refactor error components and add database issue code * Apply suggestions from code review Co-authored-by: John Bodley <4567245+john-bodley@users.noreply.github.com> Co-authored-by: John Bodley <4567245+john-bodley@users.noreply.github.com>
This commit is contained in:
@@ -16,13 +16,12 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import React, { useState } from 'react';
|
||||
// @ts-ignore
|
||||
import { Alert, Collapse } from 'react-bootstrap';
|
||||
import React from 'react';
|
||||
import { t } from '@superset-ui/translation';
|
||||
|
||||
import getErrorMessageComponentRegistry from './getErrorMessageComponentRegistry';
|
||||
import { SupersetError, ErrorSource } from './types';
|
||||
import ErrorAlert from './ErrorAlert';
|
||||
|
||||
type Props = {
|
||||
error?: SupersetError;
|
||||
@@ -39,8 +38,6 @@ export default function ErrorMessageWithStackTrace({
|
||||
stackTrace,
|
||||
source,
|
||||
}: Props) {
|
||||
const [showStackTrace, setShowStackTrace] = useState(false);
|
||||
|
||||
// Check if a custom error message component was registered for this message
|
||||
if (error) {
|
||||
const ErrorMessageComponent = getErrorMessageComponentRegistry().get(
|
||||
@@ -51,25 +48,26 @@ export default function ErrorMessageWithStackTrace({
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to the default error message renderer
|
||||
return (
|
||||
<div className={`stack-trace-container${stackTrace ? ' has-trace' : ''}`}>
|
||||
<Alert
|
||||
bsStyle="warning"
|
||||
onClick={() => setShowStackTrace(!showStackTrace)}
|
||||
>
|
||||
{message || t('An error occurred.')}
|
||||
{link && (
|
||||
<a href={link} target="_blank" rel="noopener noreferrer">
|
||||
(Request Access)
|
||||
</a>
|
||||
)}
|
||||
</Alert>
|
||||
{stackTrace && (
|
||||
<Collapse in={showStackTrace}>
|
||||
<pre>{stackTrace}</pre>
|
||||
</Collapse>
|
||||
)}
|
||||
</div>
|
||||
<ErrorAlert
|
||||
level="warning"
|
||||
title={t('Unexpected Error')}
|
||||
subtitle={message}
|
||||
copyText={message}
|
||||
source={source}
|
||||
body={
|
||||
link || stackTrace ? (
|
||||
<>
|
||||
{link && (
|
||||
<a href={link} target="_blank" rel="noopener noreferrer">
|
||||
(Request Access)
|
||||
</a>
|
||||
)}
|
||||
<br />
|
||||
{stackTrace && <pre>{stackTrace}</pre>}
|
||||
</>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user