habitica/website/common/script/libs/errorMessage.js

17 lines
562 B
JavaScript
Raw Normal View History

// errorMessage(key) will be called by all common-ops , which is also imported to the website
import _clone from 'lodash/clone';
import _template from 'lodash/template';
2019-10-15 15:17:44 +00:00
import messages from '../errors/commonErrorMessages';
export default function (msgKey, vars = {}) {
2019-10-08 14:57:10 +00:00
const message = messages[msgKey];
if (!message) throw new Error(`Error processing the common message "${msgKey}".`);
2019-10-08 14:57:10 +00:00
const clonedVars = vars ? _clone(vars) : {};
// TODO cache the result of template() ? More memory usage, faster output
return _template(message)(clonedVars);
}