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

21 lines
589 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';
2024-03-11 14:59:57 +00:00
function errorMessage (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);
}
2024-03-11 14:59:57 +00:00
export {
errorMessage,
};