mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 05:29:26 +08:00
feat: enhance error handling with optional title in AppError component (#6409)
This commit is contained in:
parent
235cbebf74
commit
8f5ae04743
@ -11,10 +11,11 @@ import React, { FC } from 'react';
|
|||||||
import { MainComponent } from './MainComponent';
|
import { MainComponent } from './MainComponent';
|
||||||
|
|
||||||
const Loading: FC = () => <div>Loading...</div>;
|
const Loading: FC = () => <div>Loading...</div>;
|
||||||
const AppError: FC<{ error: Error }> = ({ error }) => {
|
const AppError: FC<{ error: Error & { title?: string } }> = ({ error }) => {
|
||||||
|
const title = error?.title || 'App Error';
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div>App Error</div>
|
<div>{title}</div>
|
||||||
{error?.message}
|
{error?.message}
|
||||||
{process.env.__TEST__ && error?.stack}
|
{process.env.__TEST__ && error?.stack}
|
||||||
</div>
|
</div>
|
||||||
|
@ -74,7 +74,7 @@ const useErrorProps = (app: Application, error: any) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const AppError: FC<{ error: Error; app: Application }> = observer(
|
const AppError: FC<{ error: Error & { title?: string }; app: Application }> = observer(
|
||||||
({ app, error }) => {
|
({ app, error }) => {
|
||||||
const props = getProps(app);
|
const props = getProps(app);
|
||||||
return (
|
return (
|
||||||
@ -87,7 +87,7 @@ const AppError: FC<{ error: Error; app: Application }> = observer(
|
|||||||
transform: translate(0, -50%);
|
transform: translate(0, -50%);
|
||||||
`}
|
`}
|
||||||
status="error"
|
status="error"
|
||||||
title={app.i18n.t('App error')}
|
title={error?.title || app.i18n.t('App error', { ns: 'client' })}
|
||||||
subTitle={app.i18n.t(error?.message)}
|
subTitle={app.i18n.t(error?.message)}
|
||||||
{...props}
|
{...props}
|
||||||
extra={[
|
extra={[
|
||||||
|
@ -26,13 +26,16 @@ export class ErrorHandler {
|
|||||||
message += `: ${err.cause.message}`;
|
message += `: ${err.cause.message}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const errorData: { message: string; code: string; title?: string } = {
|
||||||
|
message,
|
||||||
|
code: err.code,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (err?.title) {
|
||||||
|
errorData.title = err.title;
|
||||||
|
}
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
errors: [
|
errors: [errorData],
|
||||||
{
|
|
||||||
message,
|
|
||||||
code: err.code,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user