-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(errors): add client scaffolding for custom error messages #9677
Conversation
message, | ||
link, | ||
stackTrace, | ||
}: Props) { | ||
const [showStackTrace, setShowStackTrace] = useState(false); | ||
|
||
// Check if a custom error message component was registered for this message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is essentially a no-op today as we haven't registered any error messages and this component will never get a new error object passed in.
cfdf7bb
to
c532ec4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few suggestions. non super blocking
message, | ||
link, | ||
stackTrace, | ||
}: Props) { | ||
const [showStackTrace, setShowStackTrace] = useState(false); | ||
|
||
// Check if a custom error message component was registered for this message | ||
const ErrorMessageComponent = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (error) {
const ErrorMessageComponent = getErrorMessageComponentRegistry().get(error.errorType);
if (ErrorMessageComponent) {
return <ErrorMessageComponent error={error} />
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can modify a bit to check for error
once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works for me! i optimized for repetition over nesting, but i agree this is better
@@ -84,4 +85,7 @@ export default function setupApp() { | |||
// @ts-ignore | |||
window.jQuery = $; | |||
require('bootstrap'); | |||
|
|||
// setup appwide custom error messages | |||
setupErrorMessages(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if you want to nest the call here or in App.jsx
like setupApp
and setupPlugins
. The items in setupApp
here seems likely to be removed at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put it here because it seems like there are a bunch of App.jsx
s that exist today, and we'd want all of them to have the error message registry attached to them. I assume in the future we'll end up with only one and this file will be removed, but i think it's fine to keep this here for now
* under the License. | ||
*/ | ||
|
||
// Generic errors created on the frontend |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do this so ErrorType
will also work like enum
.
// Generic errors created on the frontend
// TODO: Add more error types as we classify more errors
export const ErrorType = {
FRONTEND_CSRF_ERROR: 'FRONTEND_CSRF_ERROR',
FRONTEND_NETWORK_ERROR: 'FRONTEND_NETWORK_ERROR',
FRONTEND_TIMEOUT_ERROR: 'FRONTEND_TIMEOUT_ERROR',
} as const;
type ValueOf<T> = T[keyof T];
export type ErrorType = ValueOf<typeof ErrorType>;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
}; | ||
|
||
export type ErrorMessageComponent = | ||
| React.ComponentType<ErrorMessageComponentProps> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React.ComponentType
already includes React.FunctionComponent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this should be enough
export type ErrorMessageComponent = ReactComponentType<ErrorMessageComponentProps>;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
c532ec4
to
dce295f
Compare
CATEGORY
Choose one
SUMMARY
Beginning implementation of #9194
This PR adds scaffolding for the client side part of custom error messages. No existing behavior should be changed yet. Scaffolding consists of:
ErrorMessageComponentRegistry
for registering all error messages by error typesetupErrorMessagesExtra
Note that this registry is included in the main Superset repo. This is because we only support translations in this repo currently, and it's important to allow all the error messages registered here to have translations.
Todo in future PRs:
TEST PLAN
View a dashboard, ensure network errors and hardcoded raised errors still render properly
ADDITIONAL INFORMATION
REVIEWERS
to: @graceguo-supercat @ktmud @kristw @rusackas