The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/utils/client/lib/handleError.js

33 lines
937 B

import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import _ from 'underscore';
import toastr from 'toastr';
import { escapeHTML } from '../../../../lib/escapeHTML';
export const handleError = function(error, useToastr = true) {
if (error.xhr) {
error = error.xhr.responseJSON || {};
}
if (_.isObject(error.details)) {
for (const key in error.details) {
if (error.details.hasOwnProperty(key)) {
error.details[key] = TAPi18n.__(error.details[key]);
}
}
}
if (useToastr) {
if (error.toastrShowed) {
return;
}
const details = Object.entries(error.details || {})
.reduce((obj, [key, value]) => ({ ...obj, [key]: escapeHTML(value) }), {});
const message = TAPi18n.__(error.error || error.message, details);
const title = details.errorTitle && TAPi18n.__(details.errorTitle);
return toastr.error(message, title);
}
return escapeHTML(TAPi18n.__(error.error || error.message, error.details));
};