mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 21:27:23 +01:00
moving developer-only strings to api/common messages (#10258)
* move translatable string to apiMessages * use apiMessages instead of res.t for groupIdRequired / keepOrRemove * move pageMustBeNumber to apiMessages * change apimessages * move missingKeyParam to apiMessages * move more strings to apiMessages * fix lint * revert lodash imports to fix tests * fix webhook test * fix test * rollback key change of `keepOrRemove` * remove unneeded `req.language` param * extract more messages from i18n * add missing `missingTypeParam` message * Split api- and commonMessages * fix test * fix sanity * merge messages to an object, rename commonMessage to errorMessage * apiMessages -> apiError, commonMessages -> errorMessage, extract messages to separate objects * fix test * module.exports
This commit is contained in:
18
website/server/libs/apiError.js
Normal file
18
website/server/libs/apiError.js
Normal file
@@ -0,0 +1,18 @@
|
||||
// apiError(key) will be called by all controllers / api tests
|
||||
// it includes the api- and commonErrors, since common-ops are used in the api too
|
||||
|
||||
import _ from 'lodash';
|
||||
|
||||
import commonErrors from '../../common/errors/commonErrorMessages';
|
||||
import apiErrors from '../../common/errors/apiErrorMessages';
|
||||
|
||||
export default function (msgKey, vars = {}) {
|
||||
let message = apiErrors[msgKey];
|
||||
if (!message) message = commonErrors[msgKey];
|
||||
if (!message) throw new Error(`Error processing the API message "${msgKey}".`);
|
||||
|
||||
let clonedVars = vars ? _.clone(vars) : {};
|
||||
|
||||
// TODO cache the result of template() ? More memory usage, faster output
|
||||
return _.template(message)(clonedVars);
|
||||
}
|
||||
Reference in New Issue
Block a user