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

refactor: delete error data in error handler plugin #2575

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
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
14 changes: 9 additions & 5 deletions packages/portal/src/plugins/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const HTTP_CODES = {
401: 'Unauthorised',
403: 'Unauthorised',
404: 'NotFound',
410: 'Gone',
423: 'Locked'
};

Expand Down Expand Up @@ -31,19 +32,22 @@ function normaliseErrorWithCode(errorOrStatusCode, { scope = 'generic' } = {}) {
if (typeof errorOrStatusCode === 'object') {
error = errorOrStatusCode;
if (HTTP_CODES[error.statusCode]) {
const httpCode = HTTP_CODES[error.statusCode]; // || 'UnknownError';
const httpCode = HTTP_CODES[error.statusCode];
error.code = `${scope}${httpCode}`;
}
}

// Too much information re HTTP requests/responses to pass around to components:
// dispose of it
delete error.config;
delete error.request;
delete error.response;
delete error.toJSON;

return error;
}

function translateErrorWithCode(error, { tValues = {} }) {
// if (!this.$i18n.te(`errorMessage.${error.code}`)) {
// error.code = 'genericUnknownError';
// }

if (this.$i18n.te(`errorMessage.${error.code}`)) {
const translations = this.$i18n.t(`errorMessage.${error.code}`);
if (typeof translations === 'object') {
Expand Down
5 changes: 0 additions & 5 deletions packages/portal/src/plugins/europeana/apis/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ export default class EuropeanaApi {
error.message = error.response.data.error;
}
}
// Too much information to pass around, dispose of it
delete error.response;
delete error.config;
delete error.request;
delete error.toJSON;
}

return error;
Expand Down
Loading