Skip to content
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

fix: better error messages for dashboard properties modal #11382

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions superset-frontend/src/dashboard/components/PropertiesModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,25 @@ class PropertiesModal extends React.PureComponent {
}

async handleErrorResponse(response) {
const { error, statusText } = await getClientErrorObject(response);
const { error, statusText, message } = await getClientErrorObject(response);
let errorText = error || statusText || t('An error has occurred');
Copy link
Member

@mistercrunch mistercrunch Oct 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be good to refactor that message and similar ones in a constant in a module:

$ git grep -i "error.*occurred'" superset-frontend/
superset-frontend/src/SqlLab/components/ExploreCtasResultsButton.jsx:          this.props.errorMessage || t('An error occurred'),
superset-frontend/src/SqlLab/components/ExploreResultsButton.jsx:          this.props.errorMessage || t('An error occurred'),
superset-frontend/src/components/TableLoader.tsx:        props.addDangerToast(t('An error occurred'));
superset-frontend/src/dashboard/components/PropertiesModal.jsx:      body: error || statusText || t('An error has occurred'),
superset-frontend/src/datasource/DatasourceEditor.jsx:            error || statusText || t('An error has occurred'),
superset-frontend/src/datasource/DatasourceModal.tsx:            body: error || t('An error has occurred'),
superset-frontend/src/explore/components/DisplayQueryButton.jsx:            error: error || statusText || t('Sorry, An error occurred'),
superset-frontend/src/explore/components/PropertiesModal.tsx:      body: error || statusText || t('An error has occurred'),
superset-frontend/src/utils/getClientErrorObject.ts:            : t('An error occurred');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, let's treat that as a separate task.


if (typeof message === 'object' && message.json_metadata) {
errorText = message.json_metadata;
} else if (typeof message === 'string') {
errorText = message;

if (message === 'Forbidden') {
errorText = t('You do not have permission to edit this dashboard');
}
}

this.dialog.show({
title: 'Error',
bsSize: 'medium',
bsStyle: 'danger',
actions: [Dialog.DefaultAction('Ok', () => {}, 'btn-danger')],
body: error || statusText || t('An error has occurred'),
body: errorText,
});
}

Expand Down