2018-05-04 21:00:19 +00:00
|
|
|
// 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';
|
2018-05-04 21:00:19 +00:00
|
|
|
|
2024-03-11 14:59:57 +00:00
|
|
|
function errorMessage (msgKey, vars = {}) {
|
2019-10-08 14:57:10 +00:00
|
|
|
const message = messages[msgKey];
|
2018-05-04 21:00:19 +00:00
|
|
|
if (!message) throw new Error(`Error processing the common message "${msgKey}".`);
|
|
|
|
|
|
2019-10-08 14:57:10 +00:00
|
|
|
const clonedVars = vars ? _clone(vars) : {};
|
2018-05-04 21:00:19 +00:00
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
|
};
|